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 imagemagickMirror / flip commands
Mirror left↔right (horizontal flip):
magick input.png -flop output.pngFlip 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-toolsMirror / flip
Mirror left↔right:
pngflip -x input.png output.pngFlip top↕bottom:
pngflip -y input.png output.pngQuick verify it stayed PNG (and dimensions unchanged)
file input.png output.pngIf 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 imagemagick1) Inspect / verify (before & after)
Basic info (format, size, depth, colorspace):
magick identify input.pngMore detailed:
magick identify -verbose input.png | lessHash compare (proves it changed/unchanged):
sha256sum input.png2) Flip / rotate
Mirror left ↔ right (horizontal):
magick input.png -flop output.pngFlip top ↕ bottom (vertical):
magick input.png -flip output.pngRotate 90° right / left (lossless for square pixels; still PNG output):
magick input.png -rotate 90 output.pngRotate 180°:
magick input.png -rotate 180 output.png3) Crop / trim
Crop (WxH+X+Y):
magick input.png -crop 800x600+100+50 +repage output.pngTrim transparent/solid borders automatically:
magick input.png -trim +repage output.pngAdd padding back after trim (example: 30px transparent border):
magick input.png -trim +repage -bordercolor none -border 30 output.png4) Resize (high quality)
Resize by width (keeps aspect):
magick input.png -resize 1200x output.pngResize by percent:
magick input.png -resize 50% output.pngForce exact size (may distort):
magick input.png -resize 800x800! output.pngFit inside a box (no distortion):
magick input.png -resize 800x800 output.pngBest-practice “nice downscale” (sharpen lightly):
magick input.png -filter Lanczos -resize 50% -unsharp 0x0.75+0.75+0.008 output.png5) Lossless PNG size optimization (no visual loss)
PNG can be recompressed losslessly to smaller files.
Strip metadata (optional):
magick input.png -strip output.pngSet compression level (0–9). This is lossless; affects file size/time:
magick input.png -define png:compression-level=9 output.pngAlso reduce “bloat” from ancillary chunks (still lossless):
magick input.png -strip -define png:compression-level=9 output.png6) Convert formats (careful)
PNG → WebP lossless (if you want modern + lossless):
magick input.png -define webp:lossless=true output.webpPNG → JPG (LOSSY, not recommended if you want zero loss):
magick input.png -quality 95 output.jpg7) Colors / transparency
Make white background transparent (tune fuzz % as needed):
magick input.png -fuzz 5% -transparent white output.pngAdd a solid background behind transparency:
magick input.png -background white -alpha remove -alpha off output.pngForce/ensure alpha is present:
magick input.png -alpha on output.png8) 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.pngAppend top-to-bottom:
magick top.png bottom.png -append output.pngOverlay one on another (center):
magick base.png overlay.png -gravity center -compose over -composite output.pngOverlay with offset (example +40+30):
magick base.png overlay.png -gravity northwest -geometry +40+30 -compose over -composite output.png10) 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"; doneTrim all PNGs:
mkdir -p out && for f in *.png; do magick "$f" -trim +repage "out/$f"; doneResize all PNGs to max 1600px wide:
mkdir -p out && for f in *.png; do magick "$f" -resize 1600x "out/$f"; done11) “Don’t accidentally lose quality” rules (quick)
- Stay PNG → PNG for lossless editing.
- Avoid exporting to JPG unless you accept quality loss.
-striponly 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"; done2) Rotate a whole set (ex: 90° right)
mkdir -p out && for f in *.png; do magick "$f" -rotate 90 "out/$f"; done3) Trim borders (great for charts with extra padding)
mkdir -p out && for f in *.png; do magick "$f" -trim +repage "out/$f"; done4) 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"; done5) 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"; done6) 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"; done7) Build side-by-side pairs (dominants + chart)
If you name them like game1-chart.png and game1-dominants.png:
mkdir -p out8) 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"; doneTwo 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 *.pngsportsimg social *.pngsportsimg 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.