【问题标题】:Cloudinary Upload Fixed Image Height, Variable WidthCloudinary 上传固定图像高度,可变宽度
【发布时间】:2016-07-10 01:40:07
【问题描述】:

我要求我上传的所有图片都具有 225 像素的固定高度并适合 225x225 的正方形。宽度将根据纵横比而变化,最大为 225。

下面不允许灵活的宽度,只是让每张图片都是 225x225。

cl_image_tag("sample.jpg", array("width"=>225, "height"=>225, "crop"=>"fill"))

http://cloudinary.com/documentation/image_transformations#fill

这是我的要求:

1) 如果上传的图片为 150w x 300h。结果将是 112w x 225h。

2) 如果上传的图片是 500w x 250h。结果将是 225w x 225h。

3) 如果上传的图片是 500w x 100h。结果将是 225w x 225h。

4) 如果上传的图片是 50w x 100h。结果将是 112w x 225h。

5) 如果上传的图片是 100w x 50h。结果将是 225w x 225h。

【问题讨论】:

    标签: php jquery cloudinary


    【解决方案1】:

    需要使用chain transformations 来完成此操作。 Scale 首先使用 LIMIT fill 进行裁剪。如果图像大于裁剪框的大小,则仅限制填充裁剪,因此不会裁剪较小的图像。

    array("height"=>225, "crop"=>"scale"),
    array("width"=>225, "height"=>225, "crop"=>"lfill")
    

    完整的 PHP 代码:

        echo cl_image_upload_tag('test',
            array(
                "public_id" => "filepath",
                "format" => "jpg",
                "callback" => $cors_location,
                "html" => array(
                    "multiple" => true
                ),
                "transformation" => array(
                    array("height"=>225, "crop"=>"scale"),
                    array("width"=>225, "height"=>225, "crop"=>"lfill")
                )
            )
        );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 2018-10-08
      • 1970-01-01
      • 2014-01-12
      • 2016-08-17
      • 1970-01-01
      相关资源
      最近更新 更多