Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize to fit in a box and set background to black on "empty" part

I'm trying to obtain this result: fixed box size (133x100), the image should be resized but not stretched to fit inside that box, the empty space should be filled with black.

I'm actually trying with this command:

convert -background black -gravity center -extent 133x100 from.jpg to.jpg

However instead of fitting the image inside the requested box, I obtain a crop of the image. How to obtain the requested result? I'm digging into documentation but there are a lot of options and I still didn't find (I think) the one that I require.

like image 410
Francesco Belladonna Avatar asked Aug 29 '13 14:08

Francesco Belladonna


Video Answer


1 Answers

Looks like I've found the solution by myself with this link: http://www.imagemagick.org/Usage/thumbnails/#fit_summery

And this code solved my issue:

convert from.jpg -thumbnail 133x100 -background black -gravity center -extent 133x100 to.jpg
like image 132
Francesco Belladonna Avatar answered Sep 21 '22 13:09

Francesco Belladonna