Skip to content

Resize image to "Fit Contain" the given width/height #182

Answered by jcupitt
andrefelipe asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @andrefelipe,

Use thumbnail to fit within 1080x1080 (so one axis is cropped), then use gravity to expand to exactly the size you need. Perhaps (untested):

$image = Vips\Image::thumbnail("some-image-file.xxx", 1080);
$image = $image->gravity("centre", 1080, 1080, ["extend" => "background", "background" => 86]);
$image->WriteToFile("thumb.jpg");

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@andrefelipe
Comment options

@jcupitt
Comment options

@andrefelipe
Comment options

@jcupitt
Comment options

Answer selected by andrefelipe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants