CHROMA KEY NOTES / 011
Large Images and Browser Memory: The Practical Limits
A browser-based green screen remover must decompress every uploaded file into a raw RGBA pixel array before any keying work begins, so a 10.8 KiB PNG of 640 by 420 pixels immediately expands to 1.0 MiB of memory. The tool then holds four arrays at once during processing, so peak memory is roughly 13 times the pixel count. Images under 12 megapixels are safe on modern phones; above 45 megapixels, the browser tab will likely be killed by the operating system.
File size on disk does not predict memory in the browser
The most important thing to understand about a browser-based image tool is that file size on disk and memory in the browser are two completely different numbers. A PNG file stores pixels compressed with zlib deflate. When the browser loads it through an <img> element and then rasterizes it onto a <canvas> via drawImage(), the result is an ImageData object containing a Uint8ClampedArray of width times height times 4 bytes. Every pixel gets four bytes: red, green, blue, and alpha. There is no compression in this array. It is raw.
The tool's own sample image illustrates the gap. The file sample-green-screen.png is 10,863 bytes on disk, which is 10.8 KiB. Once decoded, its 640 by 420 pixels become 1,075,200 bytes of raw RGBA, which is 1.0 MiB. That is a 97.2 times expansion. A user who sees a 10 KiB file and assumes it will use 10 KiB of memory is off by two orders of magnitude. This is not a bug or an inefficiency in the tool; it is how every browser decodes every image format into a canvas. JPEG, GIF, WebP, and BMP all end up as the same raw RGBA array before any pixel work happens.
One Stack Overflow user demonstrated this at extreme scale with a 24000 by 12000 pixel image that was 17.2 MB on disk. Google Chrome's task manager showed 1.1 GB of memory while loading and decoding that file, which matches the decoded RGBA footprint of 288 million pixels times 4 bytes equals 1.05 GiB. The user asked why such a small file consumed so much memory; the answer is that the file is small but the pixel count is enormous.
Four arrays held simultaneously during processing
When the tool processes an image, it does not just hold the decoded RGBA. The processImage function in app.js allocates and maintains four separate arrays in memory at the same time:
- Decoded bitmap: the browser holds an internal copy of the decoded image so the
<img>element can be drawn onto the canvas. This is width times height times 4 bytes. - ImageData.data: a
Uint8ClampedArrayreturned byctx.getImageData(0, 0, w, h). This is the working copy that all three processing passes read and write. Also width times height times 4 bytes. - Int32Array queue: the flood-fill frontier in
floodFromEdges, declared asnew Int32Array(pixels)where pixels equals width times height. This is width times height times 4 bytes. - Uint8Array connected: the label array that marks each pixel as 0 (not a candidate), 1 (candidate), 2 (cleared), or 3 (pocket-visited). This is width times height times 1 byte.
Adding these together, the live memory during processing is width times height times 13 bytes. For the 640 by 420 sample, that is 3,494,400 bytes or 3.3 MiB. For a 12 megapixel phone photo at 4032 by 3024, it is 158,505,984 bytes or 151.2 MiB. For a 24 megapixel DSLR image at 6000 by 4000, it is 312,000,000 bytes or 297.5 MiB. For a 48 megapixel extreme image at 8000 by 6000, it is 624,000,000 bytes or 595.1 MiB.
These numbers are below the typical desktop tab ceiling of about 4 GiB, which is why desktop browsers can handle most images. But they are dangerously close to the mobile tab ceiling. iOS Safari typically kills tabs that exceed roughly 1 GiB of total JavaScript heap, and Chrome on Android behaves similarly on devices with limited RAM.
Three full-frame passes over every pixel
The tool iterates over every pixel three times. The scanCore function tests each pixel against the green-dominance threshold and marks candidates. The floodFromEdges function performs an 8-neighbour breadth-first search from the image perimeter, clearing all connected candidate pixels. The applyMatte function feathers edge pixels with a smoothstep alpha blend and unmixes the key color from translucent boundary pixels. Each pass visits every pixel at least once, so the minimum pixel visit count is width times height times 3.
For the 640 by 420 sample, that is 806,400 pixel visits. For a 12 megapixel photo, it is 36,578,304 visits. For a 24 megapixel DSLR image, it is 72,000,000 visits. For a 48 megapixel extreme image, it is 144,000,000 visits. On a modern desktop processor, each pixel visit takes roughly 10 to 50 nanoseconds depending on cache behavior, so a 12 megapixel image processes in about 1 to 2 seconds. On a mid-range phone, the same image takes 3 to 5 seconds. A 45 megapixel image can take 15 seconds or more, during which the browser may decide the tab is unresponsive.
The rowsPerFrame slicing trick
The tool uses a clever technique to keep the user interface responsive during long processing runs. Instead of processing the entire image in one synchronous loop, it divides the work into horizontal slices. The formula is rowsPerFrame = Math.max(1, Math.floor(400000 / w)), which targets roughly 400,000 pixels per animation frame. Each slice is processed inside a requestAnimationFrame callback, so the browser can paint the progress bar and respond to user input between slices.
At 640 pixels wide, the tool processes 625 rows per frame, which means the 420-row sample completes in a single frame. At 4032 pixels wide, it processes 99 rows per frame, requiring 31 frames to complete a 3024-row image. At 6000 pixels wide, it processes 66 rows per frame, requiring 61 frames. At 8192 pixels wide, it processes 48 rows per frame, requiring 114 frames.
However, this slicing does not reduce peak memory. All four arrays remain allocated at full size for the entire duration of processing. The slicing only prevents the UI from freezing; it does not prevent the tab from being killed if the total memory exceeds the device's limit. A user watching a progress bar fill slowly on a 45 megapixel image may still see the tab disappear when the operating system runs out of memory.
iOS Safari and the 16 million pixel canvas limit
iOS Safari enforces a hard limit on canvas dimensions. One developer reported the exact warning canvas area exceeds the maximum limit (width * height > 16777216) when rendering large PNG images on iPhone devices. That limit is 16,777,216 pixels, which is 4096 by 4096, or approximately 4 megapixels at square dimensions. A 4032 by 3024 phone photo at 12.19 megapixels exceeds this limit.
However, this limit applies to the canvas element's allocated dimensions, not to the source image's natural dimensions. The tool sets resultCanvas.width = img.naturalWidth and resultCanvas.height = img.naturalHeight, which means the canvas matches the source image exactly. On iOS Safari, a canvas larger than 4096 by 4096 may either fail silently or produce an empty result. The tool does not detect this condition; it relies on the browser to handle it.
A separate Stack Overflow report confirmed that Safari 12 crashes with Total canvas memory use exceeds the maximum limit when multiple canvases accumulate. The tool creates one canvas for the result and one temporary canvas for edge-color detection, so the total canvas footprint during processing is two canvases at the source resolution. On a 12 megapixel image, that is two canvases of 46.5 MiB each, plus the ImageData and queue arrays.
What sleek.design says about size limits
The competitor sleek.design states that the maximum image size depends on device memory and cites approximately 8000 by 8000 pixels. At 8000 by 8000, the raw RGBA array alone is 244 MiB, and the full processing footprint is approximately 781 MiB. This is below the desktop ceiling but above what most mobile devices can sustain. The competitor does not publish a mobile-specific limit or explain why large images fail differently on phones versus desktops. The competitor also does not explain the 97x expansion ratio between file size and decoded memory, which means a user who reads "8000 by 8000" may still upload a 50 MB file expecting it to work because 50 MB seems reasonable.
The competitor onlinepngtools.com does not expose a working chroma-key tool page at all; the URL returns a directory of PNG tools with no upload area, no parameters, and no size guidance. The competitor picsart.com routes image editing through a cloud-based pipeline, so memory limits are server-side and not visible to the user, but the trade-off is that the image leaves the device.
Practical guidance: always check pixel dimensions, not megabytes
The single most useful habit is to check the pixel dimensions of your image before uploading, not the file size in megabytes. A 2 MB JPEG from a 24 megapixel camera and a 2 MB JPEG from a 6 megapixel camera have very different memory footprints once decoded. The 24 megapixel image produces 91.6 MiB of raw RGBA; the 6 megapixel image produces 22.9 MiB. File size tells you nothing useful about memory.
If your image is larger than 12 megapixels and you do not need that resolution for the final output, resize it before uploading. Green screen keying does not benefit from megapixel counts beyond what the delivery target requires. A YouTube thumbnail needs 1280 by 720. An ecommerce listing needs 1000 to 2000 pixels on the longest side. A presentation slide image needs at most 1920 by 1080. A print at 300 dpi needs the physical size times 300, which for a 4 by 6 inch print is 1200 by 1800. None of these benefit from a 45 megapixel original.
On a phone, the fastest way to shrink an image is to use the Photos or Gallery app's export function and choose a medium or small size. On desktop, any image editor can resize to 1920 pixels on the longest side. The tool's edge-color detection function already downsamples to a maximum of 512 pixels for its own scan, so the key color detection is cheap regardless of image size. The expensive part is the full-resolution getImageData call and the three full-frame passes that follow.
What happens when the tab is killed
When a browser tab exceeds its memory limit, the operating system kills it. On iOS Safari, the tab closes and the user is returned to the tab list. On Android Chrome, the tab shows a "Aw, Snap" message. On desktop, the tab may freeze or crash with an "Out of Memory" message. In all cases, the image being processed is lost, and the user must start over with a smaller file.
The tool cannot prevent this. It cannot reduce the four-array footprint without fundamentally changing the algorithm. It cannot detect that the device is about to run out of memory, because browsers do not expose this information to JavaScript. The only defense is to resize before uploading.
One Stack Overflow user working with Android bitmap processing described the experience directly: they could process only 71 bitmaps before hitting an out-of-memory exception. That user was using largeHeap mode, which is the Android equivalent of asking the system for more memory. A browser-based tool cannot make that request; it operates within whatever heap the browser allocates for the tab, which is typically smaller than a native app's heap.
Questions people actually ask
- Why does my 3 MB PNG crash the browser when a 10 MB PNG works fine?
- Because pixel dimensions determine memory, not file size. A 3 MB PNG of 8000 by 6000 pixels expands to 183 MiB of raw RGBA, while a 10 MB JPEG of 1920 by 1080 expands to only 7.9 MiB. The JPEG is larger on disk but has far fewer pixels. Always check the image dimensions, not the file size in megabytes.
- What is the Safari canvas size limit?
- iOS Safari limits canvas area to 16,777,216 pixels (width times height), which is 4096 by 4096. One developer reported the warning "canvas area exceeds the maximum limit" when rendering large PNG images on iPhone. Images larger than this may produce an empty canvas or crash the tab on iOS.
- Does the progress bar mean the tool is working correctly?
- Yes, the progress bar indicates that the rowsPerFrame slicing is keeping the UI responsive. However, the slicing does not reduce peak memory. All four arrays remain allocated at full size during processing. If the total memory exceeds the device's limit, the tab may be killed even while the progress bar is visible.
- Can I upload a RAW or TIFF file?
- No. The tool accepts any file whose MIME type starts with
image/, but browsers do not decode RAW or TIFF formats through the<img>element. Export your file as PNG, JPEG, WebP, GIF, or BMP first. See which image formats work with a green screen remover for details. - Why does the same image work on desktop but crash on my phone?
- Because mobile browsers have lower memory ceilings than desktop browsers. A 24 megapixel image costs 297.5 MiB during processing, which is within a desktop tab's 4 GiB ceiling but may exceed a mobile tab's 1 GiB ceiling. Resize to 1920 by 1080 before uploading from a phone.
Where a pre-keyed file wastes the same memory
Pixel count is not the only memory fact. A PNG that already has an alpha channel stores one extra byte per pixel, and that byte is counted in the same width * height * 4 product the tool allocates. Our 640 by 420 sample costs 10,265 bytes on disk when the original green is preserved under the transparent pixels, against 7,456 bytes when the transparent pixels are zeroed to pure black, for the same 268,800 pixels and the same 209,102 clear ones. Decoded, both are exactly 1,075,200 bytes of RGBA. The compressed file is smaller; the memory is identical.
That matters when the same picture is retried. An already-transparent export cannot be re-keyed, because every pixel with alpha zero is skipped before its color is tested, so the file has to be flattened onto an opaque color and fed in again. See what happens when the input PNG already has transparency for the six measured scenarios and the flattening steps.