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"; doneGenerate @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"
doneResize all images to a max width of 750px (keeping aspect ratio):
magick mogrify -resize 750x *.pngResize all images to a max height of 750px (keeping aspect ratio):
magick mogrify -resize x750 *.pngFormat Conversion
Convert all PNGs to JPEGs:
for f in *.png; do magick "$f" "${f%.png}.jpg"; doneConvert all JPEGs to PNGs:
for f in *.jpg; do magick "$f" "${f%.jpg}.png"; doneConvert all PNGs to WebP (great for smaller file sizes):
for f in *.png; do magick "$f" "${f%.png}.webp"; doneConvert all PNGs to PDFs (useful for Xcode vector assets):
for f in *.png; do magick "$f" "${f%.png}.pdf"; doneiOS 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"
doneCompression & Optimization
Compress all PNGs (reduce file size):
magick mogrify -strip -quality 85 *.pngCompress all JPEGs to 80% quality:
magick mogrify -strip -quality 80 *.jpgCompress all PNGs using pngquant (lossy but very effective):
brew install pngquant
pngquant --quality=65-80 --ext .png --force *.pngTrimming & Cropping
Trim transparent whitespace around all PNGs (great for cleaning up icons):
magick mogrify -trim +repage *.pngCenter crop all images to a square (e.g., 512x512):
magick mogrify -gravity center -crop 512x512+0+0 +repage *.pngColor & Appearance
Convert all images to grayscale:
magick mogrify -colorspace Gray *.pngAdd a white background to all transparent PNGs:
for f in *.png; do
magick "$f" -background white -flatten "$f"
doneMake white background transparent:
for f in *.png; do
magick "$f" -transparent white "$f"
doneUseful Utility Commands
Get info (dimensions, format, size) of all images:
magick identify *.pngRename 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"
doneQuick Reference: Install Everything You Need
brew install imagemagick pngquant
Leave a Comment