Search code examples
shellterminalimagemagick

How to resize image width but keep original height?


convert input.png -resize 200x output.png

resizes the input image's width to be 200 pixels, but it also resizes the height to ensure the output has the same aspect ratio as the input.

I would like the output to have the same height as the input image instead. The output should be squashed/stretched as necessary.

E.g. if the input is 400x365 pixels, then the output should be 200x365 pixels. But if the input is 12151x832 pixels, the output should be 200x832 pixels.

According to https://stackoverflow.com/a/75380906/3310334 I've already tried

magick input.png -resize 200x'%h' output.png

But this also keeps the aspect ratio, the output image's height is not the same as the input image's height.


Solution

  • Use ! flag like this:

    magick input.png -resize 200x\! output.png
    

    More on documentation: https://imagemagick.org/Usage/resize/#noaspect