0

I would like to resize groups of photos in batch.

I see this tutorial for "Batch Mode" on GIMP.org, but it looks seriously confusing and complicated. I see a few references here on Askubuntu to something called ImageMagick, however, when I went to install it I saw 276 ratings culminating in a one-star review. I started getting depressed reading the reviews.

Please advise.

hoatzin
  • 647

3 Answers3

2

This worked for me:

  1. Put the images I wanted resized into a folder.
  2. Opened the folder into a terminal window.
  3. Installed GraphicsMagick (an active fork of ImageMagick) using sudo apt install graphicsmagick-imagemagick-compat
  4. gm mogrify -geometry 600^x600^ *.png

The gm command shown above worked very quickly to resize all the png images in the directory. The ^ symbol ensures that the image aspect ratio is maintained when the image is resized, but the resulting width or height are treated as minimum values rather than maximum values.

hoatzin
  • 647
1

I've been using Imagemagick for batch processing images in Ubuntu for years, and I don't have a single complaint. It's very powerful, which may be why it appears confusing at first.

Here's a simple Bash script using Imagemagick's mogrify command that will prompt you for the width and height of JPG images you want to scale in the current directory, strip the EXIF data, set the interlacing, sampling factor, and quality to prepare the images for the web:

#!/bin/bash
# Get the desired dimensions.
echo 'What maximum width do you want?'
read width
echo 'What maximum height do you want?'
read height
# Scale the images.
for fname in `pwd`/*.jpg; do
  mogrify -resize "${width}x${height}>" -strip -interlace Plane -sampling-factor 4:2:0 -quality 85% $fname
done

Save the file as something like, "scaleimages.sh" in your home directory's ~/bin folder--you may have to create the folder--so it will be in your PATH, and make it executable:

chmod 700 ~/bin/scaleimages.sh

To use it, open Terminal and cd into the folder where the images are that you want to scale, and run:

scaleimages.sh

The script is just an example, and isn't set up to handle file names with spaces, but it shows you how easy it can be to batch things with ImageMagick.

linux4me
  • 416
0

My system is still on ImageMagick 6:

Version: ImageMagick 6.9.12-98 Q16 x86_64 18038 https://legacy.imagemagick.org

To resize use the convert -resize command in a terminal. With a Bash for loop the command will execute over a batch of images in the current directory. As a one liner:

$ for i in *.jpg; do convert -resize 35% $i copy_of_$i; done

where $i refers to the filename to be converted and copy_of_$i prep-ends "copy_of_" to the filename to be outputted (otherwise the original is overwritten). The file is reduced to 35% of the original pixel size.

Test this logic with:

$ for i in *.jpg; do echo copy_of_$i; done

A more complex version for files named by date might rename the files and add a count to the filename:

$ filenumber=0
> for filename in 20250617*
> do convert -resize 35% $filename resized_$filenumber.jpg
> ((filenumber++))
> done

or:

$ x=0; for i in 20250617*; do convert -resize 35% $i new_doors_$x.jpg; ((x++)); done

Test this with:

$ for filename in 20250617*; do echo $filename resized_$filenumber.jpg; ((filenumber++)); done

The file is resized and a copy is saved in the format

resized_0.jpg

resized_1.jpg, etc.

Use man ImageMagick, man convert andconvert --help for convert -resize options.