121

Using the imagemagick convert command, how can I resize an image to a fixed width and proportional height e.g. using the -resize or the -thumbnail option?

Christof Aenderl
  • 4,233
  • 3
  • 37
  • 48

3 Answers3

156

Use -resize 100x to resize images to 100 pixels in width while maintaining the height's aspect ratio.

Read the fine ImageMagick manual for details.

moropus
  • 3,672
  • 1
  • 22
  • 30
  • 10
    imagemagick comes with `mogrify` which will alter original image. I found it easiser to copy the images into a new folder then run `mogrify -resize 512x *.jpg` – Lex Feb 05 '15 at 10:08
  • 2
    mkdir will complain if the directory already exists. To avoid this, add the -p flag "no error if existing" to mkdir. `mkdir -p thumbnails` explained in this question: http://stackoverflow.com/questions/4906579/how-to-use-bash-to-create-a-folder-if-it-doesnt-already-exist – Paul Rougieux Feb 09 '15 at 15:31
98

Imagemagick geometry: 'width'x'height' If you leave one part empty, this means resize proportional.

Examples:

100x200       # width = 100, height = 200
300x          # width = 300, height = proportional
x300          # width = proportional, height = 300
Christof Aenderl
  • 4,233
  • 3
  • 37
  • 48
  • 16
    `100x200` will create an image with theses dimensions. The original picture will keep its ratio W/H. `100x200\!` will also create an image with theses dimensions, but image inside will be deformed to stick the new dimensions. – MTranchant Jan 29 '15 at 09:37
  • 3
    @MTranchant & chrise : AFAICS, `-geometry 100x200` behaves as `min(100x, x200)` (ImageMagick 6.9.2.7, Fedora 23). – Skippy le Grand Gourou Apr 27 '16 at 13:05
0

For nubie's like me... Windows: Powershell: for Facebook Photos for example:

Right click windows 'Start', select 'Terminal'

C: cd to directory that you require to do conversion from: ie: cd Users/OneDrive/Pictures

C: mkdir FBName ;creates sub-directory 'makedir ./FBName' does the same.

C: magick name.jpg -resize 2048 ./FBName/newname.jpg

; Will resize 'name.jpg' with a max size of 2048 (long edge, portrait or landscape) into the subdirectory FBName that you created previously. Linux would replace 'magick' with 'convert'