Используйте метод imagecopyresized
, который есть у вас в PHP.
Больше информации о imagecopyresized
Пример:
$image_stats = GetImageSize("/picture/$photo_filename");
$imagewidth = $image_stats[0];
$imageheight = $image_stats[1];
$img_type = $image_stats[2];
$new_w = $cfg_thumb_width;
$ratio = ($imagewidth / $cfg_thumb_width);
$new_h = round($imageheight / $ratio);
// if this is a jpeg, resize as a jpeg
if ($img_type=="2") {
$src_img = imagecreatefromjpeg("/picture/$photo_filename");
$dst_img = imagecreate($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "/picture/$photo_filename");
}
// if image is a png, copy it as a png
else if ($img_type=="3") {
$dst_img=ImageCreate($new_w,$new_h);
$src_img=ImageCreateFrompng("/picture/$photo_filename");
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
imagepng($dst_img, "/picture/$photo_filename");
}
else ...