如果你的意思是他们不能大于115x115。你必须经历的过程是这样的:
如果宽度大于115,则将宽度设置为115px,将height设置为height / original_width * 115;
我有一些来自图像上传器脚本的代码来执行此操作
list($Width, $Height) = getimagesize($row["img_file"]);
if(($Width > $Height) && ($Width > 115))
{
$Height = ceil(($Height / $Width) * 115) ;
$Width = 115;
}
elseif(($Height > $Width) && ($Height > 115))
{
$Width = ceil(($Width / $Height)* 115);
$Height = 115;
}
elseif(($Height > 115) && ($Height == $Width))
{
$Height = 115;
$Width = 115;
}获得正确的尺寸后,可以使用imagecreatefromjpeg / png / gif然后使用imagecopyresampled调整图像大小。
图像上载脚本的另一部分代码,使用计算的尺寸从URL调整图像大小
if ($extension == "png")
{
$image = imagecreatefrompng($URLofImage)or die("Width Of Image: ".$widthofImage." Height Of Image: ".$heightofImage." Height: ".$height." Width: ".$width);
$image_p = imagecreatetruecolor($widthofImage, $heightofImage)or die("Width Of Image: ".$widthofImage." Height Of Image: ".$heightofImage." Height: ".$height." Width: ".$width);
imagealphablending($image_p, false);
$color = imagecolorallocatealpha($image_p, 0, 0, 0, 0);
imagesavealpha($image_p, true);
list($width, $height) = getimagesize($URLofImage);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $widthofImage, $heightofImage, $width, $height);
imagepng($image_p, "./images/thumbs/".$name, 9);
return ("./images/thumbs/".$name);
}