Imagemagick - Resize images to 25px height and aspect ratio

31,067

Solution 1

You can do all that with ImageMagick.

You're question is not very specific, so here's a quick cheat sheet of command examples that may help you:

# resize image to width 25, keeping aspect ratio
convert -geometry 25x src/image1.png out/image1.png

# resize image to height 25, keeping aspect ratio
convert -geometry x25 src/image1.png out/image1.png

# concatenate images horizontally
convert +append src/image1.png src/image2.png out/image12horiz.png

# concatenate images vertically
convert -append src/image1.png src/image2.png out/image12vert.png

In addition, the montage command is probably perfect to create the final image you are looking for (on a transparent bg with some padding, etc), but I don't remember the syntax.

Another useful command is identify, to find the dimensions of images (along with other details).

After you install ImageMagick, you can see the list of commands in man ImageMagick, and get further details on each command in the man pages. There are an awful lot of functions, but it should not be too difficult to figure out the rest on Google. (I do that all the time.)

Solution 2

Just to add something to @janos answer. I haven't used previous versions of ImageMagick but on version v6 or later according to the docs http://www.imagemagick.org/Usage/resize/#geometry

Geometry is a very special option. The operator behaves slightly differently in every IM command, and often in special and magical ways. The reasons for this is mostly due to legacy use and should be avoided if at all possible.

So other than the -geometry parameter you can still use -resize and omit the value you want in order to keep the aspect ratio. You can also use the -quality parameter to avoid image quality downgrade when resizing them. Value of quality is between 1 (lowest image quality and highest compression) and 100 (best quality but least effective compression). You can read more here: https://imagemagick.org/script/command-line-options.php#quality

For example:

# resize image to height 25, keeping aspect ratio with quality 90
convert -resize x25 original_image.jpeg -quality 90 resized_image.jpeg
Share:
31,067

Related videos on Youtube

test
Author by

test

I'm a human being. Always learning.

Updated on July 09, 2022

Comments

  • test
    test almost 2 years

    OK, so I have a folder of like 16 images all between the dimensions of 205x150 to 103x148. I want to size them down to the pixel height and width of 25px and stack them horizontally on a transparent background... is that possible?

    I should probably be using ImageMagick for this...