This guide will cover resizing a large number of images at once to be the same size. It does assume you are using Linux though, but it should work similarly on other Unix-based operating systems.
Toolset
This will use ImageMagick, install the imagemagick
package. Knowledge of changing directories and running commands on the command line is assumed, see here for details.
Resize one file
This uses the command mogrify
which overwrites the original file. The basic format is:
mogrify -resize [x]x[y] [file]
To resize a file called test.jpg to 600×900 that would be:
mogrify -resize 600x900 test.jpg
If the file’s dimensions are not in the same ratio as what is specified, the file will be resized to have the named width (x). To force it to break the ratio append ‘!’ to the dimensions.
From the command line tutorial it should be noted that resize
is an option to the command and the dimensions are the option’s value.
Resize, all have the same number of pixels
The above command resizes a 1200×1800 picture to 600×900, but a 1800×1200 to 600×400. To have both pictures resize and give equal numbers of pixels, the area of the resulting picture is specified. For this it is 540000. This is given instead of the dimensions and a ‘@’ symbol is appended to the area:
mogrify -resize 540000@ image.jpg
Should it be 1200×1800 it will become 600×900 or 1800×1200 to 600×900. If the image isn’t in the ratio 3:2 it will be resized so that is has 540000 pixels, e.g. 1800×2000 becomes 697×774. This isn’t quite the same as an image can’t have fractions of a pixel.
Non-destructive resize
Just substitute mogrify
for convert
and give the name of the new file, which is the result, as its last argument.
Many files with wildcards
As described in this tutorial wildcards can be used.
To resize all jpg images in the current directory the following would be used:
mogrify -resize [new size] *.jpg mogrify -resize [new size] *.jpg *.gif *.png #Assuming there are gifs and pngs present
To resize files in a subdirectory:
mogrify -resize [new size] */*.jpg mogrify -resize [new size] */*/*.jpg # Two directories down
Naming the directories as described in here also works.