Articles · Phones and browsers · 中文
What to know before AI-upscaling a large phone photo: size, upload and color
Many people's first attempt at AI-upscaling a phone photo ends like this: a long upload wait, then a message saying “resolution too high”; or the result finally arrives and the vivid reds and greens are a shade duller than the original. We ran into both problems while building the “Upscale” feature of our image tool pixforge. The reasons, and the measured data behind them, are below — worth knowing before you start.
Do the math first: phone originals are not small
A typical main-camera phone photo today is 4032 × 3024, about 12.2 megapixels. Upscale it 2× and the output is 8064 × 6048, about 48.8 megapixels; at 4×, the output is 16128 × 12096, about 195 megapixels. We multiplied the side lengths directly to get these numbers; as you can see, the pixel count grows with the square of the upscale factor.
That is why many AI upscaling services limit the input size, by side length or by total pixels. Our approach is to say it plainly before you click:
- When you open “Upscale”, we state, for your image's real dimensions, how large the output will become (for example, 4032 × 3024 at 2× becomes 8064 × 6048), rather than just saying “2×”.
- 4× suits only fairly small images. For an image over 4 megapixels, we suggest using 2× instead.
- A photo with a side over 4096, or more than 16 megapixels in total, cannot be upscaled directly. The reason is given before you click, along with a “shrink first, then upscale” one-click option.
There is a question worth pausing on here: does a 12-megapixel phone original really need upscaling? If it is only for posting to social media or making an avatar, it is already large enough. AI upscaling suits other things better: old photos, screenshots, images that were compressed down small, or a small region cropped out first. Crop first, then upscale usually pays off better than upscaling the whole original — that is our usage advice, not a measured conclusion.
Upload: why large images are slow, and how to speed them up
Upscaling has to send the image to a processing service. Our earliest approach encoded the whole image and relayed it through the website's server — and a 12 MP phone photo simply would not go through: it either exceeded the server's memory limit or was rejected only after the upload finished. We changed to letting the browser upload the image directly, with an upload progress display; the server reads only a small piece at the start of the file to get the real dimensions, then checks once more whether it can be processed and how it should be counted.
The second change was the upload format. Small images still go as lossless PNG; images over 4 megapixels are uploaded as quality-95 JPEG instead. Measured on an Android phone (a Redmi) with a 4032 × 3024 photo:
- Uploading the lossless PNG: about 132 seconds.
- Uploading quality-95 JPEG: about 25 seconds to upload, about 54 seconds from click to result.
The cost is that JPEG is lossy, so large images take a small compression hit at the upload step. We judged the speed gained at quality 95 to be worth it, and settled it that way. Your network will differ, and so will your times. On a China Unicom home broadband connection with no VPN, both upload and download connected fine for us.
A hidden risk: a 69-byte “bomb”
Once large images are supported, there is an attack to defend against, called a “decompression bomb”: the file itself is only a few dozen bytes, but its header declares an enormous size. If a browser decodes according to the declaration, it allocates memory for that size and blows the phone's memory straight away.
Our method is to read the width and height from the file header before decoding: PNG from IHDR, JPEG from SOF, WebP from its several headers, with approaches for GIF and BMP as well. One JPEG detail: the EXIF data may carry a thumbnail, and the thumbnail has its own SOF — when reading, skip it by segment length, or you will mistake the thumbnail's size for the main image's. Images over 40 megapixels are refused outright, with a message telling you how many megapixels this image has and what the limit is, rather than a vague “could not read”. Formats whose headers cannot be read this way (AVIF and HEIC, for example) keep the post-decode pixel check as a fallback.
We verified with a real test file: a 69-byte PNG whose header declares 20000 × 20000 — 400 megapixels. Decoded into a 4-bytes-per-pixel bitmap it would take about 1.6 GB of memory; that figure is our estimate from the declared size. On the phone it was refused immediately, with the message “this image has 400.0 megapixels, over the 40-megapixel limit”. On the same phone, an ordinary 12-megapixel photo opened as usual.
Lesson: when you write a test for a defense, confirm that the test really fails when the defense is removed. We temporarily switched the pre-check off and reran it; the test did fail — which is what shows it tests the pre-check itself, and not some other path that happened to produce a similar message.
Color: why wide-gamut photos go dull after upscaling
Photos from iPhones and other phones often carry a Display P3 wide-gamut color profile, able to represent more vivid colors than ordinary sRGB. The most common approach on the web is to draw the image onto a canvas, convert it to sRGB, and upload. That step crushes the most vivid part of the colors, and once the upscale is done, they cannot come back. (The principles of color profiles, and the traps in browsers, are covered in another article.)
Our approach has two steps: upload with the original color values kept — no conversion to sRGB, and no color profile attached; then, once the upscaled result comes back, write the original image's ICC color profile back onto it, so viewing software displays it as P3.
Using a P3 test image upscaled 2×, shrinking the result back to the original size, and comparing the average color difference ΔE against the original (smaller is closer; the ΔE here does not necessarily use the same formula as the numbers in the CMYK article, so do not compare across articles):
- Convert to sRGB first, then upload: average ΔE about 13.6.
- Keep the original values and write the ICC back: average ΔE about 4.9.
- In the most vivid red, green and orange-yellow patches, ΔE fell from 27–37 down to 2–9; greys, whites and blacks were identical under both approaches — there was no loss there to begin with.
Running the real flow on that Android phone, small images (PNG results) with the P3 profile restored measured a whole-image ΔE of about 4.87, and large images (JPEG results) about 3.89.
There is one more small trap here: when Chrome encodes JPEG with a canvas, it automatically embeds an sRGB color profile (PNG does not). What we want is “raw values with no label”, so after encoding we strip it explicitly — otherwise the upload is treated as sRGB. We only found this because, when we wrote the test asserting “the uploaded file carries no ICC”, the JPEG path failed.
One honest admission: if the write-the-ICC-back step fails, we do not throw away the processing result you have already paid for. It is saved as usual, with a note that “the colors may be slightly duller than the original”.
A checklist before you start
- Decide whether upscaling is needed at all. Phone originals are usually large already; what really needs it is often an old photo, a small image, or a cropped region.
- Crop first, upscale second. Upscale only the part you need — it saves time and is more likely to succeed.
- 2× or 4×: the 4× output has four times the pixels of the 2× output, and suits only small images.
- Work on a stable network. Uploading the large image is the most time-consuming step.
- For photos where color matters, confirm the tool preserves the color profile. Otherwise the colors will be a shade duller after upscaling.
- The result will differ slightly from the original. The AI invents detail that was not in the original, so for uses that demand complete fidelity, inspect the upscaled result yourself.
Test environment: the upload times (132 s, 25 s, 54 s), the blocking of the 69-byte forged file, and the on-device color differences (4.87 and 3.89) were all measured in Chrome on one Android phone; the set where ΔE fell from 13.6 to 4.9 (vivid colors from 27–37 down to 2–9) was a comparison run on a computer against the same processing service.
These measures are live in Jinlab's image tool pixforge. Related: Why do wide-gamut (Display P3) photos from a phone lose their color in web tools — and how do you keep it?