Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick: Resize image (rectangle to square); keep aspect ratio of main object

I have portrait and landscape JPEG images.

I want to make square thumbnails with white background from all of them. I need to keep the aspect ratio of all images and reduce the larger border to 200px.

I want to use ImageMagick (CLI) but I don't know how to do that. Any idea ?

Thumbnail generation

Here is the individual images :

Image 1Image 2

like image 878
Xavier C. Avatar asked May 08 '15 18:05

Xavier C.


People also ask

How do I resize an image in ImageMagick?

To resize an image to specific dimensions, use the convert command with an input file, the -resize parameter, your preferred dimensions, and an output filename: convert original. png -resize 100x100 new. png.

Which method will preserve aspect Ratiowhen you resize a picture?

The Constrain Proportions option lets you maintain the aspect ratio (the ratio of image width to image height). If you select this option and change the image size and resolution, the image does not stretch or shrink.


1 Answers

I think you need this:

convert -background white -gravity center   \
    input.jpg -resize 200x200 -extent 200x200 result.jpg
like image 157
Mark Setchell Avatar answered Nov 07 '22 20:11

Mark Setchell