我使用class.upload.php来调整和上传图像。我的图像需要精确的770x400。
这就是我想要完成的:
1)上传图片-完成
2)调整图像宽度为770px或高度为400px
3)使用视觉切割器(Jcrop image)将图像剪切为770x400 - DONE
我现在正在努力与第二点,因为不知道如何识别图像比例。
的例子:如果图像宽度为2156px,高度为777px,则需要将其大小调整为高度:400px,因为这会显示1100x400
如果图像的宽度为777px,高度为2156px,则需要将其调整为宽度:770px,因为这会显示770x2137
如何识别图像比例?
要调整宽度,我使用class.upload.php参数:
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 770;
要调整高度,我使用:
$handle->image_resize = true;
$handle->image_ratio_x = true;
$handle->image_y = 400;
我想我自己找到了答案。
list($read_w, $read_h, $type, $attr)= getimagesize($_FILES['file']);
$oryginalimage_ratio=$read_w/$read_h;
$desiredimage_ratio=770/400;
if($oryginalimage_ratio>$desiredimage_ratio){
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_x = 770;
}else{
$handle->image_resize = true;
$handle->image_ratio_x = true;
$handle->image_y = 400;
}