Transparent PNG becomes black after converting to JPEG
JPEG has no alpha channel, so transparent pixels keep whatever RGB is stored underneath — usually black. The correct -alpha remove fix, and why -flatten can misbehave.
You converted a PNG with transparency to JPEG and the transparent areas came out solid black:
magick logo.png logo.jpg # transparent background → black
Why
JPEG has no alpha channel. When ImageMagick discards the alpha, the underlying RGB values remain — and in most PNGs written by design tools, fully transparent pixels are stored as black with zero alpha. Remove the alpha and you reveal the black.
This is not ImageMagick misbehaving. Any tool that flattens without being told a background colour has the same problem.
The fix
magick logo.png -background white -alpha remove -alpha off logo.jpg
In order:
-background white— the colour to composite against. This is a setting, so it must come before the operators that use it.-alpha remove— composites the image over that background.-alpha off— drops the now-redundant channel so the file is smaller.
Why not -flatten?
magick logo.png -background white -flatten logo.jpg
This usually works, and you will see it recommended everywhere. The difference is that -flatten also merges layer offsets. If the PNG carries a virtual canvas — very common after a crop, and standard in GIF frames — -flatten positions the image according to that offset and you get unexpected padding or a shifted result.
-alpha remove only touches the alpha channel, so it is the more predictable choice. If you do use -flatten, add +repage first.
Any background colour
magick logo.png -background '#0d9488' -alpha remove -alpha off out.jpg
magick logo.png -background none -alpha remove -alpha off out.png
Batch a whole folder
mkdir -p jpg
for f in *.png; do
magick "$f" -background white -alpha remove -alpha off \
-quality 88 "jpg/${f%.png}.jpg"
done
The related surprises
- Rounded corners go black. Same cause — the mask lives in the alpha channel. Output PNG or WebP instead.
- A PDF page renders black. PDF pages have a transparent background, so converting straight to JPEG produces the same result. Add
-background white -alpha remove. See the PDF page. - The image goes white instead of black. Some PNG encoders store white under transparent pixels. The same fix applies — you are making the result explicit rather than depending on what the encoder happened to store.
Check before you convert
magick identify -format '%A %[opaque]\n' logo.png
The first value reports whether an alpha channel exists, the second whether every pixel is opaque. A file can have an alpha channel that is entirely opaque, in which case a straight JPEG conversion is safe.