Hallo
folgender Code ärgert mich
Damit wird ein Thumbnail von einem Bild erstellt und zwar nicht proportional sondern immer rechteckig.
Nur: Mein Thumb ist immer schwarz. Wo hab ich den Fehler?
Das Original-Script kommt von http://de.php.net/imagecopyresized
folgender Code ärgert mich
Code:
function Resize($Dir,$Image,$NewDir,$NewImage,$MaxWidth,$MaxHeight,$Quality) {
list($ImageWidth,$ImageHeight,$TypeCode)=getimagesize($Dir.$Image);
$ImageType=($TypeCode==1?"gif":($TypeCode==2?"jpeg":
($TypeCode==3?"png":FALSE)));
$CreateFunction="imagecreatefrom".$ImageType;
$OutputFunction="image".$ImageType;
if ($ImageType) {
$Ratio=($ImageHeight/$ImageWidth);
$ImageSource=$CreateFunction($Dir.$Image);
// resize image
if ($ImageWidth > $MaxWidth || $ImageHeight > $MaxHeight) {
// first resize by width (less than $MaxWidth)
if ($ImageWidth > $MaxWidth) {
$rs_w = $MaxWidth;
$rs_h = $Ratio * $MaxHeight;
} else {
$rs_w = $ImageWidth;
$rs_h = $ImageHeight;
}
// then resize by height (less than $MaxHeight)
if ($rs_h > $MaxHeight) {
$rs_w = $MaxWidth / $Ratio;
$rs_h = $MaxHeight;
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $Image, 0, 0, 0, 0, $rs_w, $rs_h, $ImageWidth, $ImageHeight);
} else {
$rs_w = $ImageWidth;
$rs_h = $ImageHeight;
$rs_image = $Image;
}
// generate resized image
imagejpeg($rs_image, $Dir.$Image, 100);
$th_image = imagecreatetruecolor($MaxWidth, $MaxHeight);
// cut out a rectangle from the resized image and store in thumbnail
$new_w = (($rs_w / 4));
$new_h = (($rs_h / 4));
imagecopyresized($th_image, $rs_image, 0, 0, $new_w, $new_h, $rs_w, $rs_h, $rs_w, $rs_h);
$OutputFunction($th_image,$NewDir.$NewImage,$Quality);
return true;
}
else
return false;
}
Nur: Mein Thumb ist immer schwarz. Wo hab ich den Fehler?
Das Original-Script kommt von http://de.php.net/imagecopyresized