Jetzt scheint es zu gehen - ich teste heute Abend nochmal...
Ich habe die Skalierung in eine eigene Funktion gepackt - das entzerrt wohl schon..
Code: Alles auswählen
<?php
// ############################# Parameter
// Maximalausmaße dreispaltiges Bild
$max_3sp_width = 1024;
$max_3sp_height = 1024;
// Maximalausmaße zweispaltiges Bild
$max_2sp_width = 728;
$max_2sp_height = 728;
// Maximalausmaße einspaltiges Bild
$max_1sp_width = 216;
$max_1sp_height = 216;
// Maximalausmaße Tumbnail
$max_thb_width = 100;
$max_thb_height = 100;
// ############################# Pfade
$html_pfad = $cfgClient[$client]["path"]["htmlpath"];
$myserver = "http://".$_SERVER['HTTP_HOST'];
// ############################# Konfigurationsvariablen
unset($startbildnummer);
unset($endbildnummer);
unset($mybildformat);
unset($myshowgallery);
unset($myshowgallerysize);
$startbildnummer = "CMS_VALUE[0]";
$endbildnummer = "CMS_VALUE[1]";
$mybildformat = "CMS_VALUE[2]";
$myshowgallery = "CMS_VALUE[3]";
$myshowgallerysize = "CMS_VALUE[4]";
if ($mybildformat=="original"){
$mybildformat ="";
}
if ($myshowgallerysize=="original"){
$myshowgallerysize ="";
}
// ############################# Funktion zum Bild umrechnen
if (!function_exists('ReSizeMyPic')){
function ReSizeMyPic($mypic, $myformat, $mypath, $mynr, $myext, $mywidth, $myheight){
$html_pfad = $cfgClient[$client]["path"]["htmlpath"];
$imagefile = $mypath."".$mypic.".".$myext;
$imagesize = getimagesize($imagefile);
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$imagetype = $imagesize[2];
$newpicpath = str_replace($myserver, "",$mypath);
switch ($imagetype){
// Bedeutung von $imagetype:
// 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM
case 1: // GIF
$image = imagecreatefromgif($imagefile);
break;
case 2: // JPEG
$image = imagecreatefromjpeg($imagefile);
break;
case 3: // PNG
$image = imagecreatefrompng($imagefile);
break;
default:
echo $imagefile.": Unsupported imageformat, only .jpg here!<br>";
}
// Verzeichnis für die skalierten Bilder erzeugen
if ( !is_dir($newpicpath."scaled") ) {
mkdir($newpicpath."scaled", 0777);
}
$picfile = "".$newpicpath."scaled/".$mypic.$myformat.".".$myext;
if(!file_exists( $picfile )){
// Ausmaße kopieren, wir gehen zuerst davon aus, dass das Bild schon picnailgröße hat
$picwidth = $imagewidth;
$picheight = $imageheight;
// Breite skalieren falls nötig
if ($picwidth > $mywidth)
{
$factor = $mywidth / $picwidth;
$picwidth *= $factor;
$picheight *= $factor;
}
/*
// Höhe skalieren, falls nötig
if ($picheight > $max_3sp_height)
{
$factor = $max_3sp_height / $picheight;
$picwidth *= $factor;
$picheight *= $factor;
}
*/
// pic erstellen
$pic = imagecreatetruecolor($picwidth, $picheight);
imagecopyresampled(
$pic,
$image,
0, 0, 0, 0, // Startposition des Ausschnittes
$picwidth, $picheight,
$imagewidth, $imageheight
);
// In Datei speichern
imagejpeg($pic, $picfile, 90);
chmod( $picfile , 0777 );
imagedestroy($pic);
}
}
}
// ############################# Ausgabe
echo "Bilder von ".$startbildnummer." bis ". $endbildnummer."<br>";
$bildnummer = 0;
for ($bildnummer=$startbildnummer; $bildnummer<=$endbildnummer; $bildnummer++){
unset($ocType);
unset($imagename);
unset($picScaleList);
unset($thisImgEditor);
unset($thisImg);
unset($output);
echo "Bilder von ".$startbildnummer." bis ". $endbildnummer."<br>";
$ocType = new cTypeGenerator();
$imagename = "";
$picScaleList = array();
$output = "";
$thisImgEditor = stripslashes($ocType->getGeneratedCmsTag('CMS_IMGEDITOR', $bildnummer));
$thisImg = stripslashes($ocType->getGeneratedCmsTag("CMS_IMG", $bildnummer));
if($edit){
$output.= "<div class='content_type_label'>";
$output.= "Bild ".$bildnummer."";
$output.= "</div>";
$output.= $thisImgEditor;
}
$imagenamearr = explode("/",$thisImg);
$imagename = array_pop( $imagenamearr );
$imagenamearr2 = explode(".",$imagename);
$imageendung = array_pop( $imagenamearr2 );
$imagename = implode(".",$imagenamearr2);
$imagepath = implode("/",$imagenamearr);
$newpicpath = str_replace($html_pfad, "",$imagepath."/");
// ############################# Bildnamen strippen
$imagename = str_replace("___3sp", "", $imagename);
$imagename = str_replace("___2sp", "", $imagename);
$imagename = str_replace("___1sp", "", $imagename);
$imagename = str_replace("___thb", "", $imagename);
if( $edit ) {
// ############################# Array aller Bilder zur Bearbeitung
if ($imagename != ""){
$picScaleList[] = array(
'mypic' => $imagename,
'mybildformat' => "___3sp",
'imagepath' => $newpicpath,
'mypicnr' => $bildnummer,
'mypicext' => $imageendung,
'mywidth' => $max_3sp_width,
'myheight' => $max_3sp_height
);
$picScaleList[] = array(
'mypic' => $imagename,
'mybildformat' => "___2sp",
'imagepath' => $newpicpath,
'mypicnr' => $bildnummer,
'mypicext' => $imageendung,
'mywidth' => $max_2sp_width,
'myheight' => $max_2sp_height
);
$picScaleList[] = array(
'mypic' => $imagename,
'mybildformat' => "___1sp",
'imagepath' => $newpicpath,
'mypicnr' => $bildnummer,
'mypicext' => $imageendung,
'mywidth' => $max_1sp_width,
'myheight' => $max_1sp_height
);
$picScaleList[] = array(
'mypic' => $imagename,
'mybildformat' => "___thb",
'imagepath' => $newpicpath,
'mypicnr' => $bildnummer,
'mypicext' => $imageendung,
'mywidth' => $max_thb_width,
'myheight' => $max_thb_height
);
}
// anzeigegröße fürs backend
if ($imagename != ""){
if ($mybildformat== "___3sp"){
$displaywidth = $max_3sp_width;
}
if ($mybildformat== "___2sp"){
$displaywidth = $max_2sp_width;
}
if ($mybildformat== "___1sp"){
$displaywidth = $max_1sp_width;
}
if ($mybildformat== "___thb"){
$displaywidth = $max_thb_width;
}
//$output.= "<img src='".$newpicpath."scaled/".$imagename.$mybildformat.".".$imageendung."' alt='Bild ".$bildnummer."'><br>";
// originalbild ausgeben um im Backend nicht auf die Skalierung warten zu müssen
$output.= "<img src='".$newpicpath.$imagename.".".$imageendung."' alt='Bild ".$bildnummer."' id='Bild ".$bildnummer."' width='$displaywidth'><br>";
}
}else{
if ($imagename != ""){
$output.= "<a href='".$newpicpath."scaled/".$imagename."___3sp".".".$imageendung."' data-lightbox='projekt'><img src='".$newpicpath."scaled/".$imagename.$mybildformat.".".$imageendung."' alt='Bild ".$bildnummer."' id='Bild ".$bildnummer."'></a><br>";
}
}
echo $output;
}
// #############################
if (!function_exists('scalepix')){
function scalePix($mypiclist){
//Alle Bilder im Array in die definierten Formate skalieren
if( $edit ) {
for ($i=0;$i<count($mypiclist);$i++){
ReSizeMyPic($mypiclist[$i]['mypic'], $mypiclist[$i]['mybildformat'], $mypiclist[$i]['imagepath'], $mypiclist[$i]['mypicnr'], $mypiclist[$i]['mypicext'], $mypiclist[$i]['mywidth'], $mypiclist[$i]['myheight']);
}
}
}}
// #############################
scalepix($picScaleList);
?>