Resizing a single image is straightforward, but processing dozens or hundreds requires automation. ImageMagick’s convert command (or the modern magick command) paired with a bash loop is the standard approach for batch image resizing on Linux.
Using ImageMagick
ImageMagick remains the most reliable tool for this task. Here’s a practical script to resize all images in a directory:
mkdir -p resize
for i in *.{jpg,jpeg,png,gif}; do
[ -f "$i" ] || continue
echo "Processing $i"
magick "$i" -resize 600 "resize/$i"
done
Key points:
mkdir -p resizecreates the output directory (the-pflag prevents errors if it already exists)- The glob pattern
*.{jpg,jpeg,png,gif}targets common image formats [ -f "$i" ] || continueskips non-matching patterns safelymagickis the modern ImageMagick command (replaces deprecatedconvert)-resize 600scales the image to 600px width, maintaining aspect ratio
To resize to a specific width and height without maintaining aspect ratio, use:
magick "$i" -resize 600x400\! "resize/$i"
The backslash-escaped ! forces exact dimensions.
Handling Filenames with Spaces
The script above already handles spaces correctly because we’re using proper quoting. The old IFS trick is unnecessary with modern bash:
mkdir -p resize
for i in *; do
[ -f "$i" ] || continue
magick "$i" -resize 600 "resize/$i"
done
The quotes around "$i" protect filenames with spaces, newlines, and special characters.
Using Parallel Processing for Speed
For large batches, process multiple images simultaneously:
mkdir -p resize
find . -maxdepth 1 -type f \( -iname "*.jpg" -o -iname "*.png" \) | \
parallel magick {} -resize 600 "resize/{/}"
Install parallel if needed (sudo apt install parallel on Debian/Ubuntu). This dramatically speeds up processing on multi-core systems.
Using FFmpeg for Additional Control
FFmpeg can handle batch image resizing with more advanced options:
mkdir -p resize
for i in *.{jpg,png}; do
[ -f "$i" ] || continue
ffmpeg -i "$i" -vf "scale=600:-1" "resize/$i" -y
done
The -vf "scale=600:-1" filter scales to 600px width with proportional height. Use scale=600:400 for fixed dimensions.
Converting Between Formats
Resize and convert formats in one step:
mkdir -p resize
for i in *.png; do
[ -f "$i" ] || continue
magick "$i" -resize 600 -quality 85 "resize/${i%.png}.jpg"
done
The ${i%.png} removes the .png extension before adding .jpg.
Checking Results
Before processing hundreds of images, test on a single file:
magick original.jpg -resize 600 test.jpg
identify test.jpg # Check dimensions and file size
Use identify to verify the output dimensions and confirm quality settings produce acceptable file sizes.
Common Gotchas
- Progressive JPEG: Use
magick -interlace Planefor web-optimized JPEGs - Transparency: PNG resizing preserves alpha channels by default; JPEGs don’t support them
- Disk space: Keep the original directory and verify the resize folder has enough space before running large batches
- ImageMagick policies: Some systems restrict ImageMagick’s functionality via
/etc/ImageMagick-6/policy.xml; adjust if needed
ImageMagick remains the standard because it handles edge cases well, produces consistent output, and integrates seamlessly with shell scripts.

Thanks but this does a shit job of handling file names with spaces