【问题标题】:PHP (class.upload.php): Resize picture depending on Width and HeightPHP(class.upload.php):根据宽度和高度调整图片大小
【发布时间】:2014-06-24 16:41:21
【问题描述】:

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

这就是我想要完成的:

1) 上传图片 - 完成

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

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;

【问题讨论】:

    标签: php resize-image


    【解决方案1】:

    我想我自己找到了答案。

    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; 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-08
      • 2021-12-28
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2012-06-19
      • 2012-05-24
      相关资源
      最近更新 更多