0

我正在使用 class class.upload.php 来调整大小和上传图像。我的图像需要精确到 770x400。

这就是我想要完成的事情:

1) 上传图片 - 完成

2) 将图像大小调整为宽度 770 像素或高度 400 像素

3) 使用视觉切割器 (Jcrop Image) 将图像切割为 770x400 - 完成

我现在正在为第二点苦苦挣扎,因为不知道如何识别图像比例。

示例:如果图像的宽度为 2156 像素,高度为 777 像素,则需要将其调整为高度:400 像素,因为这将给出 1100x400

如果图像的宽度为 777 像素,高度为 2156 像素,则需要将其调整为宽度:770 像素,因为这将给出 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;
4

1 回答 1

0

想我自己找到了答案。

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; 
}
于 2014-06-24T19:01:55.637 回答