Resize with ImageMagick with a maximal width / height

13,163

I think you need the > flag on the resize. Let's create some images (one red 300x200, another blue 1000x500):

convert -size 300x200 xc:red   small.png
convert -size 1000x500 xc:blue large.png

Now convert them both to 800x600 with no flags:

convert small.png -resize 800x600 a.png   # 800x533
convert large.png -resize 800x600 b.png   # 800x400

Now with flags:

convert small.png -resize 800x600\> a.png # 300x200
convert large.png -resize 800x600\> b.png # 800x400

You may need a caret (^) rather than a backslash on Windows.

The various flags are explained in the documentation here. Thanks to @user1133275 for the suggestion.

Share:
13,163

Related videos on Youtube

Basj
Author by

Basj

I work on R&D involving Python, maths, machine learning, deep learning, data science, product design, and MacGyver solutions to complex problems. I love prototyping, building proofs-of-concept. For consulting/freelancing inquiries : [email protected]

Updated on September 16, 2022

Comments

  • Basj
    Basj over 1 year

    The command

    imageconvert.exe in.jpg -resize 800x600 out.jpg
    

    resizes the image so that it keeps original ratio, with maximum width of 800, and maximum height of 600 pixels. But if the image is smaller both in width and height (e.g. a 300x200 image), it will be enlarged to reach 800 or 600, and I don't want this.

    How to keep the same kind of resizing (when width > 800 or height > 600), but such that an image that is smaller both in width and height (e.g. a 300x200 image), will be untouched?

  • Basj
    Basj over 7 years
    Indeed! It's -resize 800x600^> on Windows.
  • Mark Setchell
    Mark Setchell over 5 years
    @user1133275 Many thanks for the helpful suggestion - I have updated my answer.