First hands-on: converting images between formats with magick, forcing the output format via the extension or a format prefix, controlling quality and compression for JPEG, PNG, WebP, AVIF, and JXL, and verifying results with magick identify.

After dissecting the ImageMagick architecture in episode 2 — the single magick command, coder modules, delegates, and the pixel model — now it's time for real hands-on work. This episode is the point where you start taking control: we convert images between formats with a single line of command.
Format conversion is the most basic and at the same time the most frequently used capability in the real world. Every time a website receives a PNG upload from a user and then stores it as WebP, every time a script turns a photo into a JPEG thumbnail, every time a PDF document is converted into an image — that's format conversion. Let's master the foundation.
Use the sample.png we created in episode 0. The simplest conversion is done by naming the input and output — the output format is determined by the file extension:
magick sample.png sample.jpgThis is the magic of IM7: no convert command like in IM6, no extra options needed. ImageMagick reads the PNG through the png coder, translates it to its internal pixel model, then writes the JPEG through the jpeg coder. One important issue to remember: JPEG does not support transparency. If the input has an alpha channel, the JPEG result will fill the transparent area with black. For areas where transparency matters, use PNG, WebP, or AVIF.
Vector formats like SVG are not stored as a collection of pixels, but as geometric instructions. ImageMagick (with a delegate) rasterizes SVG into pixels:
magick input.svg output.pngTip
For sharp raster results, raise the density before converting: magick -density 300 input.svg output.png. SVG scales without limits, so a high density produces more pixels — the equivalent of printing with a finer printer for finer detail.
The main rule in ImageMagick: the extension determines the format. But you can also force the format with a format: prefix on the output file name — useful when the extension is misleading or absent:
magick sample.jpg png:output.dat
magick identify output.datThe second command (magick identify) reads output.dat and reports that its contents are actually PNG — even though the extension is .dat. This prefix is also used on input, for example magick png:sample.jpg to force reading a file as PNG.
Note the difference from the -format option: that option is not for output, but for formatting the informational text output — usually used with the identify subcommand:
magick identify -format "%f %wx%h %[colorspace]" sample.pngThe result is a line like sample.png 640x480 sRGB — the patterns %f, %wx%h, %[colorspace] are placeholders filled in by ImageMagick. You'll keep using this trick for scripting and verification.
The JPEG format uses lossy compression — trading a little quality for a much smaller file size. The -quality option (0-100) controls this trade-off:
magick sample.png -quality 90 output-90.jpg
magick sample.png -quality 60 output-60.jpgls -lh output-*.jpg| Quality | Characteristics |
|---|---|
| 90-100 | Excellent quality, large size |
| 75-85 | Common sweet spot for photos on the web |
| 40-60 | Small size, artifacts start to appear |
| Below 40 | Very small, clearly degraded quality |
Important
Rule of thumb: for photos, -quality 80 gives a balance that's hard to beat. But remember, JPEG is lossy — every time you save again, quality degrades. Don't make JPEG your "working format"; keep the master as PNG and export JPEG only for distribution.
PNG is lossless — no quality is lost — but that's no excuse to ignore file size. PNG stores a lot of metadata that can be dropped and uses compression whose level can be increased:
magick sample.png -strip -define png:compression-level=9 output.png
magick identify -format "%f %wx%h %b" output.png-strip removes unimportant metadata (such as profiles and comments), and png:compression-level=9 requests maximum compression. The result can be much smaller with identical quality — this is a mandatory step for website assets.
Modern formats offer better compression than JPEG at the same quality. Converting is just as easy — as long as the relevant delegate is compiled into your build:
magick sample.png -quality 80 output.webp
magick sample.png -quality 50 output.avif
magick sample.png -quality 75 output.jxl| Format | Characteristics |
|---|---|
| WebP | Modern web standard, broad support, supports alpha |
| AVIF | The best compression today, based on AV1 |
| JXL (JPEG XL) | Supports lossy and lossless, potential JPEG successor |
-quality plays a different role in each format — in WebP it means something similar to JPEG, in AVIF the range differs — but the command pattern is consistent. Check format support in your build with magick -list format | grep -i avif.
magick identifyAfter every conversion, get into the habit of verifying: are the format, dimensions, and colorspace what you expected?
magick identify sample.jpg
magick identify -format "%f %wx%h %[colorspace] %b" output.webpoutput.webp WEBP 640x480 640x480+0+0 8-bit sRGB 24.5KB 0.010u 0:00.009Reading this output: file name, format (WEBP), dimensions (640x480), depth (8-bit), colorspace (sRGB), size (24.5KB), and processing time. If the numbers don't make sense — for example the dimensions changed even though you didn't ask for a resize — investigate immediately.
In this episode 3, you've done your first hands-on work: converting PNG to JPEG, rasterizing SVG to PNG, forcing formats with a prefix, understanding JPEG quality and compression, optimizing PNG, exporting to the modern formats WebP, AVIF, and JXL, and verifying results with magick identify.
The key takeaways:
format: prefix to force it.-quality around 80 for web photos.-strip and png:compression-level=9.magick identify is the most important verification tool — learn to read its output.In the next episode 4, we'll cover resize, crop, and transforms — mastering geometry with -resize, -scale, and -thumbnail, understanding the aspect ratio operators (^, !, %, >, <), cropping with -crop, and transforming with -rotate, -flip, -flop, -trim, -extent, and -gravity. See you in episode 4!