Articles · Images and color · 中文

How to convert CMYK images to RGB accurately in the browser

By mosjin · 2026-10-01 · Based on real development work and on-device testing

Print artwork from a designer, or files back from a print shop, often arrive as CMYK JPEGs. Many web tools either refuse them outright or hand them to the browser to convert — and the converted colors are not quite right. When building our image tool pixforge, we tested this specifically: where the browser's built-in conversion goes wrong, what we replaced it with, and how large an image a phone can handle.

Why CMYK is a problem

Screens emit light by adding red, green and blue, so web and phone images are almost all RGB. Printing lays four inks — cyan (C), magenta (M), yellow (Y) and black (K) — onto paper, so print files commonly use CMYK, with four numbers per pixel instead of three.

CMYK cannot be displayed on a screen directly; it has to be converted to RGB. The difficulty: the same four numbers do not look the same printed on coated paper as on newsprint. So a CMYK file usually carries an ICC color profile stating “these numbers correspond to this paper and these inks”. A conversion has to use that profile as its basis to compute the color a screen should show.

Browser support for CMYK has always been inconsistent. Faced with CMYK, the easiest thing for a web image tool is to refuse it. That is what we did at first, too: block it, and say “this is a CMYK image” in the notice, so users would not think their file was broken.

The browser's built-in conversion: pure black ink goes brown

Later we wanted to open CMYK up. Our first idea was to let the browser convert it, since browsers already have color management. Before building on that, we ran a comparison test.

The test file was a CMYK JPEG carrying a FOGRA39L_coated color profile (FOGRA39 is the European standard for coated-paper printing). We had desktop Chromium convert it, then compared region by region against the open-source color engine LittleCMS:

  • In three color regions, the browser and LittleCMS differed by 0 to 3 (out of 255) — effectively identical.
  • In a region with only black ink and none of the other three inks (channel values 0, 0, 0, 120), the browser produced (155, 138, 133), a brownish grey; LittleCMS produced (163, 164, 164), a neutral grey.
  • We tried all four rendering intents; the browser's result never matched, with the largest deviation between 25 and 32.

In other words, the problem is not “colors outside the RGB range” — the conversion itself is inaccurate in exactly the regions of neutral grey and pure black ink. Those regions are the most common colors in text, line art and black-and-white photos, and a brown cast makes a whole black-and-white print job look yellowed at a glance.

Lesson: our plan originally said “let the browser convert accurately; only a few colors outside sRGB will be slightly compressed”. That sentence was written from impression. Testing showed it does not hold — fortunately before launch. From now on, before writing “accurate” or “lossless” anywhere, we compare the whole image against a reference implementation, and look specifically at neutral greys and pure black ink, the areas most likely to go wrong.

Our approach: decode it ourselves, convert it ourselves

Since the browser cannot be trusted with this, we bypass it and do both steps ourselves:

  1. Extract the raw four-channel data. We use the JPEG decoder from the PDF reader pdf.js (Apache-2.0 licensed), which returns the original CMYK numbers rather than the browser's converted RGB. Both common encodings — Adobe-style CMYK and YCCK — are supported.
  2. Convert colors with LittleCMS. We use lcms-wasm, LittleCMS compiled to WebAssembly (MIT licensed), converting to sRGB in the browser according to the image's own ICC profile. The conversion uses relative colorimetric intent with black point compensation, matching Photoshop's defaults.

Preview and export use the same conversion result, so what you see on screen is exactly what you export. We compared our output against LittleCMS reference results across the whole image: maximum difference no more than 3, average difference under 0.04, and pure-black-ink regions stay neutral grey instead of going brown.

One case we still refuse: four-channel JPEGs without the Adobe marker. That encoding is rare, and we cannot reliably determine what its values mean; guessing wrong would corrupt every color. We detect it from the file header alone — no wasted full decode before failing — and the notice states the reason.

What about CMYK files with no color profile?

Not every CMYK file carries a profile. Without one, there is no basis for “which paper and inks these numbers mean”, so a default standard has to be chosen. We chose FOGRA39, the general European standard for coated-paper printing; its profile file comes from the open-source colord project (CC0-1.0 licensed) and is downloaded only when such an image appears — images that carry a profile download nothing extra.

How accurate is that default? We measured that too, using the color difference ΔE2000 (smaller is closer; around 2 or below is generally hard for an untrained eye to notice):

  • If the artwork really was prepared for coated-paper printing, the average color difference is only 1.6 to 2.7.
  • If it was prepared for uncoated or newsprint stock, the average difference is about 10 to 15 — a visible deviation.
  • For comparison, the browser's original approach averaged about 17, but that figure uses the older ΔE76 formula and cannot be compared directly with the ΔE2000 numbers above.

So the default is not perfect: for coated-paper work it is already quite close; for uncoated or newsprint work the deviation remains noticeable. For such images, the interface shows a gentle notice — “no color profile; estimated using the coated-paper standard” — rather than hiding that this is an estimate. With your consent to statistics, we also record one anonymous flag noting only whether the CMYK image you opened carried a profile, so we can learn how common this case actually is.

How far can a phone go?

CMYK has four numbers per pixel, and conversion takes three steps — decode, color conversion, display — so memory and time both run far above an ordinary image. On a Huawei phone with 4 GB of memory (browser engine Chromium 132), we measured three sizes using a profile-carrying CMYK JPEG:

Image sizeOpen timePeak memoryExport PNG
12 megapixels11 s223 MB2.8 s
20 megapixels13 s350 MB4.1 s
24 megapixels15 s397 MB4.7 s

None of the three sizes crashed, though opening does take ten-plus seconds. Based on this data, we capped CMYK images at 24 megapixels: anything over the cap, or a CMYK image whose dimensions cannot be read, is stopped before decoding with the reason stated, instead of freezing the phone. A profile-less 12-megapixel image retested at the same 11 seconds, with peak memory of 224 MB.

The figures above were measured on that 4 GB Huawei phone; if the CMYK decoding code changes in the future, they will be measured again.

When it fails, say the real reason

The conversion components load afterwards, so they can fail to load on a network problem; they can also fail because the phone is out of memory, the file is damaged, or its encoding is rare. Each failure gets its own specific notice — “the conversion component failed to load; you can retry”, “not enough memory” — never a blanket “something went wrong”. Only when users know the reason do they know whether to retry, change the file, or change the device.

If you also process images on the web, our advice is simple: when you hit a color problem that “the browser should handle”, run one whole-image comparison against a reference implementation before deciding to trust it.

This CMYK handling is live in Jinlab's image tool pixforge — just open a CMYK image to use it. Related: Why do wide-gamut (Display P3) photos from a phone lose their color in web tools — and how do you keep it?