<?
//calculate thumb size
$ow = imagesx($im);
$oh = imagesy($im);
$maxh = 100;
$maxw = 150;
$new_h = $oh;
$new_w = $ow;
if($oh > $maxh || $ow > $maxw){
$new_h = ($oh > $ow) ? $maxh : $oh*($maxw/$ow);
$new_w = $new_h/$oh*$ow;
}
//create dst image
$dst_img = ImageCreateTrueColor($new_w,$new_h);
//resize and copy image
ImageCopyResized($dst_img, $im, 0,0,0,0, $new_w, $new_h, ImageSX($im), ImageSY($im));
$function_image_new($dst_img,$galdir.$file);
?>
Create thumbnail
最新推荐文章于 2024-11-26 02:00:29 发布
本文介绍了一种使用PHP进行图片尺寸调整的方法。通过计算原始图片的宽度和高度,并根据指定的最大宽度和高度来调整图片大小,确保缩放后的图片能够适应不同的显示需求。此过程包括创建目标图像、调整大小及复制原始图像到新图像。
3万+

被折叠的 条评论
为什么被折叠?



