Guten Tag,
ich habe folgenden Code (damals irgendwo aus dem Internet). Bei manchen Fotos dreht er das Foto allerdings. Ich verstehe nicht warum und wann der Code dies macht. Im Anhang die Fotodaten, bei dem das Foto gedreht wird,
Hat hier jemand eine Idee?
ich habe folgenden Code (damals irgendwo aus dem Internet). Bei manchen Fotos dreht er das Foto allerdings. Ich verstehe nicht warum und wann der Code dies macht. Im Anhang die Fotodaten, bei dem das Foto gedreht wird,
Hat hier jemand eine Idee?
PHP-Code:
$inputfile = $upload_dir."/".$neuerName.".jpg";
$max_width = 300;
$max_height = 300;
$outputfile = $upload_dir."/n/".$neuerName.".jpg";
$quali = 90;
if (substr(strtolower($inputfile), -3) == 'jpeg' || substr(strtolower($inputfile), -3) == 'jpg')
$srcimg = imagecreatefromjpeg($inputfile);
elseif (substr(strtolower($inputfile), -3) == 'gif')
$srcimg = imagecreatefromgif($inputfile);
elseif (substr(strtolower($inputfile), -3) == 'png')
$srcimg = imagecreatefrompng($inputfile);
if (!$srcimg)
return false;
else {
$img_width = imagesx($srcimg);
$img_height = imagesy($srcimg);
/* Skalieren */
if ($img_width > $max_width && $img_height > $max_height) {
if ($img_height > $img_width) {
$img_height = ceil($img_height*($max_width/$img_width));
$img_width = $max_width;
}
else {
$img_width = ceil($img_width*($max_height/$img_height));
$img_height = $max_height;
}
}
$thumbimg = imagecreatetruecolor($img_width, $img_height);
imagecopyresampled($thumbimg,
$srcimg,0,0,0,0,$img_width,
$img_height,
imagesx ($srcimg),
imagesy($srcimg));
/* Zuschneiden */
$cutted_w = 0;
$cutted_h = 0;
if ($img_width > $max_width)
$cutted_w = ($img_width-$max_width);
if ($img_height > $max_height)
$cutted_h = ($img_height-$max_height);
/* Auffüllen */
$fill_w = 0;
$fill_h = 0;
if ($img_width < $max_width)
$fill_w = ($max_width-$img_width);
if ($img_height < $max_height)
$fill_h = ($max_height-$img_height);
$dstimg = imagecreatetruecolor($max_width, $max_height);
imagefill($dstimg, 0, 0, imagecolorallocate($dstimg, 255, 255, 255));
imagecopyresampled($dstimg, $thumbimg,
$fill_w/2,$fill_h/2,
$cutted_w/2,$cutted_h/2,
$img_width-$cutted_w, $img_height-$cutted_h,
$img_width-$cutted_w, $img_height-$cutted_h);
if (substr(strtolower($inputfile), -3) == 'jpeg' || substr(strtolower($inputfile), -3) == 'jpg') {
if ($outputfile !== false)
imagejpeg($dstimg, $outputfile, $quali);
else
imagejpeg($dstimg);
}
elseif (substr(strtolower($inputfile), -3) == 'gif') {
if ($outputfile !== false)
imagegif($dstimg, $outputfile);
else
imagegif($dstimg);
}
elseif (substr(strtolower($inputfile), -3) == 'png') {
if ($outputfile !== false)
imagepng($dstimg, $outputfile);
else
imagepng($dstimg);
}
imagedestroy ($srcimg);
imagedestroy ($thumbimg);
imagedestroy ($dstimg);
}
Kommentar