imgx — ImageMagick without the incantations#
One subcommand per thing you actually do to an image: compress, resize, convert,
crop, rotate, strip, thumbnail. Everything writes to output/ beside the source,
so the original is never touched. Quick card: imgx-cheat.
Full magick underneath: imgx raw ….
Compress — the one you reach for#
imgx compress a.png→output/a-compressed.png. Defaults:-q 85for jpeg/webp,-c 256colours for png.imgx compress a.png out.jpg— the destination extension picks the codec path, so this compresses and converts in one step.-q N— jpeg/webp quality, 1–100. 85 is a good default; 70–80 is barely distinguishable on photographs and noticeably smaller.-c N— png colour count via quantisation. 256 → 128 → 64 is where the real png savings live, far more than any compression-level tweak.
Every path also runs -strip, so metadata goes with it.
What each knob actually does#
| Format | Path taken | The lever that matters |
|---|---|---|
| jpg / jpeg | -strip -quality N |
-q. Lossy, DCT-based; quality is the whole story. |
| webp | -strip -quality N |
-q. Usually 25–35% under jpeg at matched quality. |
| png | -strip -colors N -depth 8 + max deflate |
-c. png is lossless, so the only real saving is fewer colours. |
| anything else | -strip -quality N |
falls back to the quality path |
png's compression level is already pinned at maximum (compression-level=9, filter 5, strategy 1) — turning it up further is not a thing. If a png is not shrinking, it has too many colours, not too little deflate.
Which format for which image#
The decision that changes the outcome far more than any flag.
- Photographs, anything with gradients — jpeg or webp. Lossy is correct here; the eye does not miss what the DCT throws away.
- Screenshots, UI, diagrams, line art, text — png. jpeg puts ringing artefacts around every hard edge. Shrink it with
-c, not by switching to jpeg. - Transparency needed — png or webp. jpeg has no alpha channel at all; converting to jpeg silently composites onto black.
- Logos, icons, anything that will be scaled — svg if you have it. No raster format survives resizing the way vectors do.
- Web delivery, modern browsers only — webp, essentially always smaller than the jpeg or png it replaces.
- Already-lossy source — recompressing jpeg to jpeg loses more every time. Go back to the original if one exists.
Resize#
Geometry strings pass straight through to ImageMagick, so its full grammar works.
imgx resize a.png— default 1024x1024, aspect kept, never upscales.
-s value |
Effect |
|---|---|
800x600 |
fit inside the box, aspect kept |
800x600! |
! forces exact WxH — aspect broken |
50% |
scale by percent |
x600 |
height only, width follows |
800x600^ |
^ fills the box, may overflow (pair with -extent to crop to it) |
800x600> |
shrink only, never enlarge — what the default uses |
Thumbnail, crop, rotate, strip, convert#
imgx thumb a.png— 256px square, centre-cropped to fill. Not a plain resize: the result is exactly square regardless of the input's shape.-s 128for any other side length.imgx crop a.png -s 400x400+100+50— geometry is WxH+X+Y: size first, then offset from the top-left corner.imgx rotate a.png -a 90— clockwise. Negative angles go counter-clockwise;-a 180flips without mirroring.imgx strip a.png— metadata only. Drops EXIF, GPS coordinates and colour-profile cruft with no recompression, so the pixels are bit-identical. This is the one to use before posting anything from a phone.imgx convert a.png a.webp— format comes from the destination extension, not a flag. Works on anything magick reads: heic, tiff, avif, psd, pdf pages.
Batch#
imgx batch ./dir compress -c 128 runs a subcommand over every png/jpg/jpeg/webp in a directory. Any subcommand and its flags work:
imgx batch ./avatars thumb -s 128imgx batch ./shots resize -s 1600x1600imgx batch ./photos strip
Results land in dir/output/. Originals are untouched — this is the whole reason batch is safe to run twice.
Output layout#
Omit the destination and imgx builds one:
SRC's-directory/output/NAME-suffix.ext (output/ created if absent)
| Subcommand | Suffix |
|---|---|
| compress | -compressed |
| resize | -resized |
| crop | -cropped |
| rotate | -rotated |
| thumb | -thumb |
| strip | -stripped |
Give an explicit destination and it is used verbatim, extension and all.
info#
imgx info a.png wraps identify -verbose and greps the lines worth reading: dimensions, format, colorspace, depth, filesize. Falls back to plain identify if the verbose parse finds nothing.
raw — full magick, no training wheels#
imgx raw ARGS… passes everything to magick verbatim. Anything the subcommands do not expose lives here.
imgx raw a.png b.png +append out.png— join side by side (-appendstacks vertically).imgx raw a.png -format '%wx%h' info:— identify one-liners.
Flags worth knowing when you drop to raw#
| Flag | Does |
|---|---|
-gravity center -extent WxH |
pad or crop to an exact canvas, anchored |
-background none |
keep transparency when extending the canvas |
-auto-orient |
apply EXIF rotation before anything else — do this first or crops land wrong |
-sampling-factor 4:2:0 |
jpeg chroma subsampling; meaningfully smaller files |
-interlace Plane |
progressive jpeg / interlaced png |
-unsharp 0x0.75+0.75+0.008 |
the standard post-downscale sharpen |
Why a wrapper and not an alias#
magick is one binary covering several hundred operators whose order is significant — -resize before -crop and after it are different pictures, and -strip after -quality throws away the setting. The subcommands here fix an order that is correct for the common case and pick defaults that are not landmines: never upscale, always strip, always write somewhere new.
An alias could not do the destination-extension routing that makes imgx compress a.png out.webp a single step, and it could not keep originals safe under batch. When the fixed order is wrong for what you want, raw is right there.