ImageMagick for iOS Developers: Essential Terminal Commands for Bulk Image Processing

If you've been developing iOS apps for any length of time, you know the drill — you get a folder full of images and suddenly you're resizing, converting, compressing, and generating @1x, @2x, and @3x variants for what feels like the hundredth time. Doing this manually in a design tool or image editor is tedious, error-prone, and a terrible use of your time. The good news is that your Mac's Terminal, paired with a free tool called ImageMagick, can handle all of this in seconds with a single command. In this post, I've put together a collection of the most common bulk image conversion commands I use regularly in my iOS development workflow. Just "cd" into your image folder (or right click on a folder and run "New Terminal at Folder", run a command, and let your Mac do the heavy lifting. Whether you need to batch resize, change formats, generate app icons, or optimize file sizes, there's a one-liner here for you.

Resize all PNGs to a specific size:

mkdir resized
for f in *.png; do magick "$f" -resize 1024x1024 "resized/$f"; done

Generate @2x and @1x from @3x images (common for iOS assets):

mkdir @2x @1x
for f in *.png; do
  magick "$f" -resize 66.67% "@2x/$f"
  magick "$f" -resize 33.33% "@1x/$f"
done

Resize all images to a max width of 750px (keeping aspect ratio):

magick mogrify -resize 750x *.png

Resize all images to a max height of 750px (keeping aspect ratio):

magick mogrify -resize x750 *.png

Format Conversion

Convert all PNGs to JPEGs:

for f in *.png; do magick "$f" "${f%.png}.jpg"; done

Convert all JPEGs to PNGs:

for f in *.jpg; do magick "$f" "${f%.jpg}.png"; done

Convert all PNGs to WebP (great for smaller file sizes):

for f in *.png; do magick "$f" "${f%.png}.webp"; done

Convert all PNGs to PDFs (useful for Xcode vector assets):

for f in *.png; do magick "$f" "${f%.png}.pdf"; done

iOS App Icon Generation

Generate all common iOS app icon sizes from a single 1024x1024 source:

sizes=(20 29 40 58 60 76 80 87 120 152 167 180 1024)
for s in "${sizes[@]}"; do
  magick AppIcon.png -resize ${s}x${s} "AppIcon-${s}x${s}.png"
done

Compression & Optimization

Compress all PNGs (reduce file size):

magick mogrify -strip -quality 85 *.png

Compress all JPEGs to 80% quality:

magick mogrify -strip -quality 80 *.jpg

Compress all PNGs using pngquant (lossy but very effective):

brew install pngquant
pngquant --quality=65-80 --ext .png --force *.png

Trimming & Cropping

Trim transparent whitespace around all PNGs (great for cleaning up icons):

magick mogrify -trim +repage *.png

Center crop all images to a square (e.g., 512x512):

magick mogrify -gravity center -crop 512x512+0+0 +repage *.png

Color & Appearance

Convert all images to grayscale:

magick mogrify -colorspace Gray *.png

Add a white background to all transparent PNGs:

for f in *.png; do
  magick "$f" -background white -flatten "$f"
done

Make white background transparent:

for f in *.png; do
  magick "$f" -transparent white "$f"
done

Useful Utility Commands

Get info (dimensions, format, size) of all images:

magick identify *.png

Rename all @3x files and generate @2x and @1x versions:

mkdir @2x @1x
for f in *@3x.png; do
  base="${f/@3x/}"
  magick "$f" -resize 66.67% "@2x/${base%.png}@2x.png"
  magick "$f" -resize 33.33% "@1x/${base%.png}@1x.png"
done

Quick Reference: Install Everything You Need

brew install imagemagick pngquant