image magick commands cheat sheet. Flip, rotate, and batch process images

image magick commands cheat sheet. Flip, rotate, and batch process images

I have a png image that I simply want to flip or mirror the other direction. What is the linux command to do this or install the packages needed to accomplish this. Note, i dont want to lose detail of the image, and I want details of the image to be left intact, meaning, I don't want to compress it or lose any quality or anything else

ChatGPT 5.2 said:
Use a lossless tool and keep it as PNG. These commands will not recompress as JPEG or reduce detail.

Option A (best): ImageMagick

Install

Ubuntu/Debian:

sudo apt update && sudo apt install -y imagemagick

Mirror / flip commands

Mirror left↔right (horizontal flip):

magick input.png -flop output.png

Flip top↕bottom (vertical flip):

magick input.png -flip output.png

(Older systems may use convert instead of magick, but magick is the modern entry point.)


Option B (super simple): pngflip (from libpng tools)

Install

Ubuntu/Debian:

sudo apt update && sudo apt install -y libpng-tools

Mirror / flip

Mirror left↔right:

pngflip -x input.png output.png

Flip top↕bottom:

pngflip -y input.png output.png

Quick verify it stayed PNG (and dimensions unchanged)

file input.png output.png

If you tell me whether you mean mirror left-right or flip upside-down, I’ll point you to the exact one-liner you want (but the above covers both).

You said:
can you write up a cool cheat-sheet for various magick commands to do different things with it?

ChatGPT said:
Absolutely. Here’s a “keep it crisp” ImageMagick (magick) cheat-sheet focused on PNG workflows (lossless when you stay in PNG and avoid lossy formats).


🧙 ImageMagick magick PNG Cheat-Sheet (Linux)

0) Install + sanity check

sudo apt update && sudo apt install -y imagemagick

1) Inspect / verify (before & after)

Basic info (format, size, depth, colorspace):

magick identify input.png

More detailed:

magick identify -verbose input.png | less

Hash compare (proves it changed/unchanged):

sha256sum input.png

2) Flip / rotate

Mirror left ↔ right (horizontal):

magick input.png -flop output.png

Flip top ↕ bottom (vertical):

magick input.png -flip output.png

Rotate 90° right / left (lossless for square pixels; still PNG output):

magick input.png -rotate 90  output.png

Rotate 180°:

magick input.png -rotate 180 output.png

3) Crop / trim

Crop (WxH+X+Y):

magick input.png -crop 800x600+100+50 +repage output.png

Trim transparent/solid borders automatically:

magick input.png -trim +repage output.png

Add padding back after trim (example: 30px transparent border):

magick input.png -trim +repage -bordercolor none -border 30 output.png

4) Resize (high quality)

Resize by width (keeps aspect):

magick input.png -resize 1200x output.png

Resize by percent:

magick input.png -resize 50% output.png

Force exact size (may distort):

magick input.png -resize 800x800! output.png

Fit inside a box (no distortion):

magick input.png -resize 800x800 output.png

Best-practice “nice downscale” (sharpen lightly):

magick input.png -filter Lanczos -resize 50% -unsharp 0x0.75+0.75+0.008 output.png

5) Lossless PNG size optimization (no visual loss)

PNG can be recompressed losslessly to smaller files.

Strip metadata (optional):

magick input.png -strip output.png

Set compression level (0–9). This is lossless; affects file size/time:

magick input.png -define png:compression-level=9 output.png

Also reduce “bloat” from ancillary chunks (still lossless):

magick input.png -strip -define png:compression-level=9 output.png

6) Convert formats (careful)

PNG → WebP lossless (if you want modern + lossless):

magick input.png -define webp:lossless=true output.webp

PNG → JPG (LOSSY, not recommended if you want zero loss):

magick input.png -quality 95 output.jpg

7) Colors / transparency

Make white background transparent (tune fuzz % as needed):

magick input.png -fuzz 5% -transparent white output.png

Add a solid background behind transparency:

magick input.png -background white -alpha remove -alpha off output.png

Force/ensure alpha is present:

magick input.png -alpha on output.png

8) Text overlay / watermark

Simple text in bottom-right:

magick input.png -gravity southeast -pointsize 36 -fill white -stroke black -strokewidth 2 \

Semi-transparent watermark:

magick input.png \( -size 600x120 xc:none -fill white -gravity center -pointsize 48 \

9) Combine images

Append side-by-side:

magick left.png right.png +append output.png

Append top-to-bottom:

magick top.png bottom.png -append output.png

Overlay one on another (center):

magick base.png overlay.png -gravity center -compose over -composite output.png

Overlay with offset (example +40+30):

magick base.png overlay.png -gravity northwest -geometry +40+30 -compose over -composite output.png

10) Batch processing (one-liners)

Mirror every PNG in a folder into out/:

mkdir -p out && for f in *.png; do magick "$f" -flop "out/$f"; done

Trim all PNGs:

mkdir -p out && for f in *.png; do magick "$f" -trim +repage "out/$f"; done

Resize all PNGs to max 1600px wide:

mkdir -p out && for f in *.png; do magick "$f" -resize 1600x "out/$f"; done

11) “Don’t accidentally lose quality” rules (quick)

  • Stay PNG → PNG for lossless editing.
  • Avoid exporting to JPG unless you accept quality loss.
  • -strip only removes metadata (often fine).
  • PNG “compression level” changes file size, not image detail.

If you tell me what kind of images you’re mostly working with (screenshots, logos with transparency, photos, charts), I’ll tailor this cheat-sheet into a smaller “daily driver” set of commands you’ll actually use.

You said:
Thanks, that's very useful. I'll post this on mcwai as a reference. I'll most likely be using batch command for SportsAspects charts and other images for SportsAspects. But right now, I can't think of any examples right now.

ChatGPT said:
Nice — and you’re thinking the right way: batch-first for SportsAspects.

Here are a few ready-to-use batch patterns that cover 90% of chart/image housekeeping you’ll run into. All of these keep the output as PNG (no JPG quality loss).

Batch “daily drivers” for SportsAspects

1) Mirror every PNG into out/

mkdir -p out && for f in *.png; do magick "$f" -flop "out/$f"; done

2) Rotate a whole set (ex: 90° right)

mkdir -p out && for f in *.png; do magick "$f" -rotate 90 "out/$f"; done

3) Trim borders (great for charts with extra padding)

mkdir -p out && for f in *.png; do magick "$f" -trim +repage "out/$f"; done

4) Standardize width (keeps aspect ratio)

Example: force everything to 1200px wide:

mkdir -p out && for f in *.png; do magick "$f" -resize 1200x "out/$f"; done

5) Lossless “optimize PNG size” (strip metadata + max compression)

mkdir -p out && for f in *.png; do magick "$f" -strip -define png:compression-level=9 "out/$f"; done

6) Add a consistent transparent border (useful for uniform thumbnails)

Example: 40px padding:

mkdir -p out && for f in *.png; do magick "$f" -bordercolor none -border 40 "out/$f"; done

7) Build side-by-side pairs (dominants + chart)

If you name them like game1-chart.png and game1-dominants.png:

mkdir -p out

8) Make “social tall” versions (1080x1350) without distortion

This fits inside and pads the rest:

mkdir -p out && for f in *.png; do magick "$f" -resize 1080x1350 -gravity center -background none -extent 1080x1350 "out/$f"; done

Two pro tips (so you don’t shoot yourself in the foot)

  • If you ever want to be extra safe, write outputs to out/ (as above) so originals are untouched.
  • When you’re ready, we can turn the exact workflows you use into a single script like:
    • sportsimg mirror *.png
    • sportsimg social *.png
    • sportsimg combo chart+dominants

When you run into your first real batch case (even just a folder of 5 images), paste an ls -1 of the filenames and tell me the target (thumbnail size? social? Ghost header?) and I’ll lock you into a clean, repeatable command set.