Ich habe irgendwann irgendwo das Modul Picture gefunden und erfolgreich eingebunden. Ich verwende auf einer Seite mehrmals dieses Modul. Und möchte zulassen jedem Bild eigene Größe eingeben, was mir natürlich nicht gelingt.
Das ist mein Intput:
Code: Alles auswählen
?><?php
/**
* $Revision: 1.3 $
* $Source: D:/cvs/cvsrepo/test/PPI_Nade/module/picture/input.php,v $
* $Date: 2005/11/29 16:10:51 $
*/
/**
* picture
* @author Andreas Kummer
* @copyright Copyright © 2005 w3concepts AG
*/
if (!class_exists('pictureInput')) {
class pictureInput {
function pictureInput($pfad) {
$this->pfad = $pfad;
$this->pathlen = strlen($this->pfad);
}
function getPath($root,$level = 0) {
$content = $this->readDir($root);
foreach ($content as $file) {
if (is_dir($root.$file)) {
$verzeichnis = substr($root,$this->pathlen);
$returnvalue["{$verzeichnis}{$file}/"] = str_repeat(" ",$level * 5).$file;
$returnvalue = array_merge($returnvalue,$this->getPath($root.$file."/",$level+1));
}
}
return $returnvalue;
}
function readDir($path) {
$handle = opendir($path);
while ($file = readdir ($handle)) {
if ($file != "." && $file != "..") $returnvalue[] = $file;
}
closedir($handle);
return $returnvalue;
}
function makeSelect($preselection) {
$pfad = $this->getPath($this->pfad);
foreach ($pfad as $key => $value) {
echo "$key :: $value<br/>\n";
if ($preselection == $key) {
echo "<option value=\"$key\" selected=\"selected\">$value</option>";
} else {
echo "<option value=\"$key\">$value</option>";
}
}
}
}
}
$pfad = new pictureInput($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload']);
echo "<table cellspacing=\"0\" cellpadding=\"10\" border=\"0\">";
[color=#FF4000]echo "<tr><td>Maximale Bildbreite [px]:</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[2]\" value=\"CMS_VALUE[2]\" size=\"3\" /></td>";
echo "<tr><td>Maximale Bildhöhe [px]:</td>";
echo "<td><input type=\"text\" name=\"CMS_VAR[1]\" value=\"CMS_VALUE[1]\" size=\"3\" /></td>";[/color]
echo "</table>";
Code: Alles auswählen
<?php
/**
* $Revision: 1.4 $
* $Source: D:/cvs/cvsrepo/test/PPI_Nade/module/picture/output.php,v $
* $Date: 2005/11/28 17:03:08 $
*/
/**
* picture
* @author Andreas Kummer
* @copyright Copyright © 2005, w3concepts AG
*/
if (!class_exists('picture')) {
class picture {
/**
* Klassenkonstruktor.
* @param String Absoluter Pfad zum Bild.
*/
function picture($bildpfad) {
global $cfgClient, $client;
if (empty($bildpfad)) return false;
$this->bildpfad = $bildpfad;
//$this->link = $link;
/*
* Initialwerte fest legen
*/
$this->setIniValues();
/*
* Datenbankverbind initialisieren
*/
$this->db = new DB_contenido();
/*
* Bildpfad und Dateiname ermitteln
*/
$dirname = dirname($bildpfad)."/";
$dirname = str_replace ($cfgClient[$client]['path']['htmlpath'].$cfgClient[$client]['upload'],'',$dirname);
$filename = basename($bildpfad);
/*
* Bildpfad setzen
*/
$this->path = $this->createImage($dirname,$filename);
/*
* Popup-Titel setzen
*/
// $this->setPopupTitle();
}
function setIniValues() {
global $cfgClient, $client;
$bildzielpfad = "CMS_VALUE[0]";
$this->bildzielpfad['frontend'] = $cfgClient[$client]['path']['htmlpath'].$cfgClient[$client]['upload'].$bildzielpfad;
$this->bildzielpfad['backend'] = $cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload'].$bildzielpfad;
$this->bildhoehe = "CMS_VALUE[1]";
$this->bildbreite = "CMS_VALUE[2]";
}
function setPopupTitle() {
global $cfg, $idart, $lang;
$this->db->query("SELECT pagetitle FROM {$cfg['tab']['art_lang']} WHERE idart = $idart AND idlang = $lang");
$this->db->next_record();
$this->title = $this->db->f('pagetitle');
}
function createImage($dirname, $filename) {
global $cfgClient, $client;
$src_image_size = getimagesize($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload'].$dirname.$filename);
$this->srchoehe = $src_image_size[1];
$this->srcbreite = $src_image_size[0];
if ($src_image_size[0]/$this->bildbreite > $src_image_size[1]/$this->bildhoehe) {
$resizeFactor = $src_image_size[1]/$this->bildhoehe;
} else {
$resizeFactor = $src_image_size[0]/$this->bildbreite;
}
$newBildbreite = round($src_image_size[0]/$resizeFactor);
$newBildhoehe = round($src_image_size[1]/$resizeFactor);
$bilddateiname = "{$this->bildbreite }_{$this->bildhoehe }_$filename.jpg";
$dst_im = imagecreatetruecolor($this->bildbreite,$this->bildhoehe);
if ($src_image_size[2] == 1) {
$src_im = imagecreatefromGIF($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload'].$dirname.$filename);
} elseif ($src_image_size[2] == 2) {
$src_im = ImageCreateFromJPEG($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload'].$dirname.$filename);
} elseif ($src_image_size[2] == 3) {
$src_im = ImageCreateFromPNG($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload'].$dirname.$filename);
} else {
$src_im = imagecreatefromgd($cfgClient[$client]['path']['frontend'].$cfgClient[$client]['upload'].$dirname.$filename);
}
if(($newBildhoehe >= $this->bildhoehe)&&($newBildbreite >= $this->bildbreite)){
/* Create the target image with the max size, crop it afterwards. */
//imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $this->bildbreite , $this->bildhoehe , $this->srcbreite, $this->srchoehe);
imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $newBildbreite , $newBildhoehe, $this->srcbreite , $this->srchoehe);
} else if(($newBildhoehe >= $this->bildhoehe)&&($newBildbreite < $this->bildbreite)){
$this->diff = $this->bildbreite/$newBildbreite;
echo "else if diff ".$this->diff."<br>";
$this->bildhoehe = round($newBildhoehe * $this->diff);
echo "else if new hoehe ".$this->bildhoehe;
/* Create the target image with the target size, resize it afterwards. */
//imagecopy($dst_im, $src_im, 0, 0, 0, 0, $newBildbreite, $this->bildhoehe);
imagecopyresampled($dst_im, $src_im, 0, 0, 0, 0, $this->bildbreite , $this->bildhoehe , $this->srcbreite, $this->srchoehe);
}
imagejpeg ($dst_im,$this->bildzielpfad['backend'].$bilddateiname,100);
return $this->bildzielpfad['frontend'].$bilddateiname;
}
function outputPicture($imgDescr = null, $linkDescr = null) {
global $edit;
if ($edit) {
$this->outputPictureEdit($imgDescr);
return false;
}
$img = "<img src=\"{$this->path}\" border=\"0\" width=\"{$this->bildbreite}\" height=\"{$this->bildhoehe}\" margin-right=\"20px\">";
$breite = $this->bildbreite;
if($this->bildbreite&&$this->bildhoehe){
if (empty($imgDescr)) {
echo '<div style="width:'.$breite.'px;border-left:1px solid #cccccc;border-top:1px solid #cccccc;px;border-bottom:1px solid #cccccc;px;border-right:1px solid #cccccc; padding:0px 8px 8px 0">'.$img.'</div>';
} else {
echo '<div style="margin-bottom:10px;"><div style="width:'.$breite.'px;border-left:1px solid #cccccc;border-top:1px solid #cccccc;px;border-bottom:1px solid #cccccc;px;border-right:1px solid #cccccc; padding:0px 8px 8px 0">'.$img.'</div><div class="imgDescr">'.$imgDescr.'</div></div>';
}
}
}
function outputPictureEdit($imgDescr) {
if (!empty($this->path)) {
echo "<img src=\"{$this->path}\" border=\"0\" width=\"{$this->bildbreite}\" height=\"{$this->bildhoehe}\">";
}
echo "<br />";
echo $imgDescr;
echo "<br />";
}
}
}
if (!$edit) {
echo '<script type="text/javascript" src="js/pictureResized.js"></script>'."\n";
}
if (isset($slide_modul_nr)) $slide_modul_nr++;
else $slide_modul_nr = 1;
switch ($slide_modul_nr)
{
case 1 : $bild1 = new picture("CMS_IMG[2]");
$bild1->outputPicture("CMS_IMGDESCR[2]");
break;
case 2 : $bild2 = new picture("CMS_IMG[3]");
$bild2->outputPicture("CMS_IMGDESCR[3]");
break;
case 3 : $bild3 = new picture("CMS_IMG[4]");
$bild3->outputPicture("CMS_IMGDESCR[4]");
break;
case 4 : $bild4 = new picture("CMS_IMG[5]");
$bild4->outputPicture("CMS_IMGDESCR[5]");
break;
case 5 : $bild5 = new picture("CMS_IMG[6]");
$bild5->outputPicture("CMS_IMGDESCR[6]");
break;
case 6 : $bild6 = new picture("CMS_IMG[7]");
$bild6->outputPicture("CMS_IMGDESCR[7]");
break;
case 7 : $bild7 = new picture("CMS_IMG[8]");
$bild7->outputPicture("CMS_IMGDESCR[8]");
break;
case 8 : $bild8 = new picture("CMS_IMG[9]");
$bild8->outputPicture("CMS_IMGDESCR[9]");
break;
case 9 : $bild9 = new picture("CMS_IMG[10]");
$bild9->outputPicture("CMS_IMGDESCR[10]");
break;
case 10: $bild10 = new picture("CMS_IMG[11]");
$bild10->outputPicture("CMS_IMGDESCR[11]");
break;
}
?>
Wie könnte ich die eingegebenen Höhe und Breite korrekt zu jedem Bild zuordnen ( nicht überschreiben) und die entsprechenden Berechnungen durchführen. Jetzt ist es so, dass die Eingaben nur vom ersten Bild verwendet werden, da ja auch nur die Platzhalter CMS_VALUE[1] und CMS_VALUE[2] zur Verfügung stehen.
Danke für Tipps