Getting a JPG out of anything
Four decoders, a colour space that has to be corrected, and a transparency question only you can answer.
4 min read
Four roads to the same destination
JPEG is the format everything is expected to be able to open, which is why converting to it is such a common errand. The difficulty is entirely on the way in: the files people need converted are the ones ordinary software refuses, and no single library reads them all.
So the input is identified from its bytes and sent down whichever road can decode it. Most formats are read directly. The awkward three each get a specialist, invoked as a program with an argument list rather than a command line assembled from a filename.
- PNG, WebP, TIFF, GIF, BMP, SVG
- Read directly by the imaging library and encoded straight out as JPEG.
- HEIC and HEIF
- Decoded to PNG first. The library is only trusted with these once it has proved it can actually produce pixels, because it will happily report metadata for a codec it cannot decode.
- PSD
- The flattened composite is taken — layer zero — rather than an attempt at interpreting the layer stack. Detected by the 8BPS signature at the start of the file, not by the extension.
- Camera RAW
- CR2, CR3, NEF, ARW, DNG, ORF and RW2 are developed to a 16-bit TIFF with the camera white balance applied, then encoded.
Transparency needs a decision
JPEG has no alpha channel. There is no version of this file format that can hold "nothing here", so every transparent pixel in the source has to become some actual colour before it is written.
Left unstated, the underlying library drops the channel and composites against black — which turns every logo with a clear background into a logo on a dark tile, and is where most of the surprise in this conversion comes from. This tool asks instead: the flatten colour is an option, it defaults to white, and it is applied deliberately on every path.
If what you want is the transparency kept, JPEG is the wrong destination. A PNG or a WebP keeps it, and one of those is the honest answer to that requirement.
The colours have to be moved as well
Files that came out of a print workflow are usually CMYK, and a CMYK TIFF written out as though its four channels were three comes back with its colours inverted — an unmistakable result that is easy to ship because nothing errors.
Every image is therefore converted to sRGB explicitly before encoding, whatever space it arrived in. The orientation tag is applied at the same point, before anything downstream measures the picture, so a photograph that displayed upright as a HEIC is upright as a JPEG.
Output is progressive, and quality is yours to set — 85 by default, which is high enough that the conversion is not the weakest step in whatever you do next.
Files with more than one picture inside
A multi-page TIFF and an animated GIF are both several images in one container, so "convert this to a JPG" is ambiguous. You can take the first, which is usually what a scan or an animation is standing in for, or you can take all of them and get one numbered JPG per page.
Numbering starts at one, because that is how people count pages, and each page is decoded on its own rather than as part of the whole stack. A fifty-page document therefore costs one page of memory at a time instead of fifty.
Frequently asked questions
- Why was my RAW file rejected?
- Either the format is from a vendor outside the supported list, or the decoder on this server could not develop it. Both are reported as a per-file failure with the reason, and the rest of the batch still converts.
- My converted PNG has a white background. Can I change it?
- Yes — the flatten colour is a setting. Pick the colour the image will sit on and the edges of the subject will blend into it properly instead of showing a white halo.
- Is anything kept from the original file?
- Camera metadata is dropped unless you ask for it to be kept. That is deliberate: photographs carry the camera, the settings and often the exact location, and a conversion is a common moment for that to escape unnoticed.
- How large a file can I send?
- Fifty megabytes per file and two hundred across a task of up to thirty files. RAW files are large, so a full card of them will usually need to be split across several runs.