CODE function resize($image,$width,$height = 0,$scale = false) {
$src = @GetImageSize($image);
$src_w = $src[0];
$src_h = $src[1];
if(is_array($src)) {
$quotient = $src_w / $src_h;
if($height==0) $height = $width * $quotient;
if($width==0) $width = $height * $quotient;
if($scale && $src_w < $width && $src_h < $height) {
$src_w = $src_w + $width;
$src_h = $src_h + $height;
}
if($src_w > $width) {
$dst_w = $width;
$dst_h = $dst_w / $quotient;
}
if($src_h > $height) {
$dst_h = $height;
$dst_w = $dst_h * $quotient;
}
if($src_h == $src_w) {
$dst_h = $src_h;
$dst_w = $src_w;
}
if ( $dst_h > $height || $dst_w > $width) {
$dst_h = $height;
$dst_w = $dst_h * $quotient;
if ($dst_w > $width) {
$dst_w = $width;
$dst_h = $width / $quotient;
}
}
if($src_w < $width && $src_h < $height) {
$dst_w = $src_w;
$dst_h = $src_h;
}
$dst = array("width" => $dst_w, "height" => $dst_h);
}
return $dst;
}
public static function resizeToFile($sourcefile, $dest_x, $dest_y, $targetfile = false, $endung = "jpg", $jpegqual = 90) {
if(!$targetfile) $targetfile = $sourcefile;
/* Get the dimensions of the source picture */
$picsize=getimagesize("$sourcefile");
$source_x = $picsize[0];
$source_y = $picsize[1];
switch($endung) {
case "gif": $source_id = imageCreateFromGIF("$sourcefile"); break;
case "png": $source_id = imageCreateFromPNG("$sourcefile"); break;
default: $source_id = imageCreateFromJPEG("$sourcefile");
}
$targetfile = str_replace($endung, "jpg", $targetfile);
/* Create a new image object (not neccessarily true colour) */
$target_id=imagecreatetruecolor($dest_x, $dest_y);
/* Resize the original picture and copy it into the just created image
object. Because of the lack of space I had to wrap the parameters to
several lines. I recommend putting them in one line in order keep your
code clean and readable */
$target_pic=imagecopyresampled($target_id,$source_id, 0,0,0,0, $dest_x,$dest_y, $source_x,$source_y);
/* Create a jpeg with the quality of "$jpegqual" out of the
image object "$target_pic".
This will be saved as $targetfile */
imagejpeg ($target_id,"$targetfile",$jpegqual);
return $targetfile;
}
mit Resize die Maße fürs Thumbnail berechnen und mit resizeToFile speichern (oder beides kombinieren, je nachdem wie du's brauchst).
Die erste Funktion von mir und die zweite weiß ich nimmer wann die in meine Lib gekommen ist
Viel Erfolg damit