Resize image to "Fit Contain" the given width/height #182
-
So embarrassed to ask this, I did look a lot myself, in web, in Sharp source code and libvips too, sorry. How to do in PHP a resize of a image to contain inside an area and fill the empty space with a color? The result I need is: Exactly like the Sharp resize API, with the "fit" option: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey @andrefelipe, Use $image = Vips\Image::thumbnail("some-image-file.xxx", 1080);
$image = $image->gravity("centre", 1080, 1080, ["extend" => "background", "background" => 86]);
$image->WriteToFile("thumb.jpg"); |
Beta Was this translation helpful? Give feedback.
Hey @andrefelipe,
Use
thumbnail
to fit within 1080x1080 (so one axis is cropped), then usegravity
to expand to exactly the size you need. Perhaps (untested):