简体   繁体   中英

Cloudinary Upload Fixed Image Height, Variable Width

I require all my image uploads to have a fixed height of 225px and fit in a 225x225 square. The width will vary based on the aspect ratio with a maximum of 225.

The below doesn't allow for a flexible width and just makes every image 225x225.

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

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

Here are my requirements:

1) If the image uploaded is 150w x 300h. The result will be 112w x 225h.

2) If the image uploaded is 500w x 250h. The result will be 225w x 225h.

3) If the image uploaded is 500w x 100h. The result will be 225w x 225h.

4) If the image uploaded is 50w x 100h. The result will be 112w x 225h.

5) If the image uploaded is 100w x 50h. The result will be 225w x 225h.

Needed to use chain transformations to accomplish this. Scale first then crop using LIMIT fill . Limit fill only crops if the image is bigger than the size of the crop box, therefore smaller images are not cropped.

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

Full PHP code:

    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")
            )
        )
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM