我正在尝试在PHP中将图像批量调整到250 x 250的大小
所有源图像都远大于250 x 250,所以这很有用。
我想保持长宽比,但都是250 x 250。我
知道
图像的一部分将被剪切下来。这对我来说不是问题
问题是,我当前的脚本只在宽度上工作,并根据方面设置高度,但有时,图像最终会变成250 x 166。我不能用那个。
因此,需要以相反的方式调整大小(高度到宽度)
脚本如何才能始终使最终图像250 x 250不拉伸。再说一遍,我不在乎有没有修剪。我想在某个地方会有另一个,但现在这已经超出我的想象了。我更像是一个前端人物。
任何帮助都会很好。
以下只是我完整脚本的相关部分:
$width = 250;
$height = true;
// download and create gd image
$image = ImageCreateFromString(file_get_contents($url));
// calculate resized ratio
// Note: if $height is set to TRUE then we automatically calculate the height based on the ratio
$height = $height === true ? (ImageSY($image) * $width / ImageSX($image)) : $height;
// create image
$output = ImageCreateTrueColor($width, $height);
ImageCopyResampled($output, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
// save image
ImageJPEG($output, $destdir, 100);