ImageMagick: How resize image to certain width with no pixelation (shrink but not grow)?

Posted on 2011-05-04
Last Modified: 2013-11-19
I bet ImageMagick can do this but Googling hasn't turned up any easy answers:

Given a source image I want to scale an image DOWN to 600 pixels across but I don't want the image to grow up to 600px.

   800px width -> 600px
   600px width -> 600px
   400px width -> 400px (leave at 400... don't pixelate)

Here is my current command line which pixelates:
convert input.jpg -thumbnail 600 output.jpg
What option(s) can I pass to accomplish this?
Question by:ZuZuPetals
    LVL 38

    Accepted Solution

    In ImageMagick (as with most image viweres and editors) the dimensions of an image are specified as Width x Height in that order.  X = Width, Y = Height.  In the ImageMagick help file you are looking for the "image geometry" related parameter:  -resize which you will see discussed at length in your help file:


    or online here:

    In most cases, unless you deliberately force it using operators, the geometry-related parameters maintain the aspect ratio of the original image being converted.

    You can use the "less than" operator < with your new dimensions when using -resize to ensure that the image will only be resized if the new dimensions are smaller than the original dimensions you specify (ie. only reduce, don't enlarge). Conversely, the "greater than" operator > means "resize only if the new dimensions are greater than the original dimensions", ie. "only enlarge".

    Using an 1600 x 1200 image as the source, the following command should work:

    convert InFile.jpg -resize "x600>" OutFile.jpg

    Verify that on a couple of test images smaller than 800 x 600 and larger than 800 x 600 and ensure that it works.

    You don't always need to quote the dimensions in your -thumbnail or -resize command, but if using any operators like > you must enclose them AND the operator in quotes.
    LVL 38

    Expert Comment

    Whoops!! REVERSE that > operator to <

    The operator is referring to the NEW dimension, not to the dimensions of the original image.  So "greater than" > means "if the NEW dimensions are greater than the original", and the "less than" < means "if the NEW dimensions are less than the original".


    Just in case you had expected to see two dimensions specified in the above command eg. "800x600", it is explained in the helpfile that you don't always need both.  In this case I only used the Width dimension and < operator) "x600<" so that large images will be downsized to 600 pixels ON THE WIDTH while scaling the height down to maintain the original aspect ratio

    LVL 2

    Author Closing Comment


    I found that 600> is the correct geometry.  I think it is > and not <.

    Also, I want to enforce width so the "x" is wrong (x implies re-size based on height).
    LVL 38

    Expert Comment

    Yes, sorry about that.  I haven't been too good at multi-tasking today.  Tired out and brain-dead.  Thanks for correcting.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I've been using this technique since Adobe CS2, and it should work with any version of Illustrator that includes the appearance panel. In this tutorial we'll create a button using the appearance panel in Adobe Illustrator, and then save it as a r…
    In a previously published article ( here at Experts Exchange, I explained how to achieve duplex (double-sided) scanning in Nuance's PaperPor…
    Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…
    In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now