Every online marketplace has image rules. Mercado Libre — the largest e-commerce site in Latin America — is no exception: JPG or PNG, under 10 MB, between 500 and 1920 pixels per side, zoom enabled above 800 px, digital white background.
The problem isn't that the rules are secret. They're published in the developer docs. The problem is that a seller only learns their photo was rejected after filling in the entire listing. By then the dimensions, the weight, the background — none of it is checked until upload time.
I wanted to flip that around: tell the seller what's wrong with their photo before they ever hit publish, without shipping their product photos to a server.
The constraint that shaped everything
The validator reads the file locally and never uploads it. That isn't a privacy slogan — it's an architectural constraint:
-
File APIgives the page a read-only handle to a file the user picked -
object URL(URL.createObjectURL) lets an<img>decode it in memory -
<canvas>gives pixel access for the one rule that can't be answered from metadata alone
No form submit. No /upload endpoint. No image ever becomes a network request. A seller can open DevTools → Network, run the check, and watch zero requests fire.
That constraint is useful because it kills a whole category of features before you waste time on them. If a rule needs server state, a database, or a trained model, it doesn't ship.
What can actually be verified in a browser
Most of the rules are metadata questions, so they're cheap and exact:
const ext = (file.name.split('.').pop() || '').toLowerCase();
const formatOk = ['jpg', 'jpeg', 'png'].includes(ext);
const sizeOk = file.size / (1024 * 1024) <= 10;
img.onload = () => {
const w = img.naturalWidth, h = img.naturalHeight;
const minOk = w >= 500 && h >= 500;
const maxOk = w <= 1920 && h <= 1920;
const zoomOk = w > 800; // marketplace enables the magnifier above 800 px
};
Format, weight, minimum and maximum dimensions, zoom threshold — these are unambiguous. The browser either reads the value or it doesn't.
The interesting one is the background rule. "Digital white background" is a visual property, not metadata. To check it without a server, I shrink the image to 120×120, sample only the outer 15% band, and count pixels where all three channels exceed 243:
const c = document.createElement('canvas');
c.width = c.height = 120;
const ctx = c.getContext('2d', { willReadFrequently: true });
ctx.drawImage(img, 0, 0, 120, 120);
const data = ctx.getImageData(0, 0, 120, 120).data;
const step = 3; // sample every 3rd pixel, ~40 samples per edge
let white = 0, total = 0;
for (let y = 0; y < 120; y += step) {
for (let x = 0; x < 120; x += step) {
const edge = x < 18 || x > 102 || y < 18 || y > 102;
if (!edge) continue;
const i = (y * 120 + x) * 4;
total++;
if (data[i] > 243 && data[i+1] > 243 && data[i+2] > 243) white++;
}
}
const whiteRatio = white / total; // >= 0.8 -> "likely compliant"
This is a heuristic, not image segmentation. It works well enough to catch the common failure — a grey or cream background — but it shouldn't pretend to be more precise than it is.
The part I'm most careful about: saying what it can't do
It would be easy to ship a green "ALL CHECKS PASSED" badge and call it a day. That would be dishonest, because several marketplace rules are simply not machine-checkable with these tools:
- Watermarks, logos, QR codes and contact details — text/logo detection needs a model, not a pixel sample. Not attempted.
- Category exceptions — some Fashion and Home categories allow a staged background. The general rule doesn't apply there, and the validator doesn't know the listing's category.
- The exact "white" the reviewer uses — 243-per-channel is my threshold, not an official definition. A near-white that passes here could still be judged off-white.
- The final decision — the marketplace's own moderation has the last word, always.
So the result screen separates three states: pass, fail, and review manually. The white-background check is explicitly labeled "estimated". The copy says "rules that can be checked", not "guaranteed acceptance".
I've found this honesty is a feature, not a liability. Sellers trust a tool that says "I can't tell you this" far more than one that confidently approves everything.
Implementation details that cost me time
Two small gotchas worth recording:
willReadFrequently: true. Without it, getImageData on a canvas that's read repeatedly triggers a browser warning and can silently switch to a slower GPU-backed path. It matters here because the background sampler reads as it walks the pixel grid.
Cross-origin taint. Reading pixels from an <img> whose source is another origin throws a SecurityError. Object URLs from a local File are same-origin, so this tool is safe — but it's the classic reason a canvas validator that also accepts pasted image URLs falls over. Wrap getImageData in a try/catch and degrade to "check manually" rather than crashing the page.
What this taught me about client-side tools
The best client-side validators don't try to replace the platform's review — they answer the subset of questions that have a deterministic answer locally, and are explicit about the rest. That's a narrower promise, but a much more trustworthy one.
The validator is live at ComprimeFotos if you want to try it with a product photo. The rules it checks come from Mercado Libre's official image documentation — worth reading if you're building something similar for another marketplace.
A question for the comments: if you've built a client-side validator against a third-party platform's rules, how did you handle the rules that are technically checkable but context-dependent — where the answer depends on data (category, account, region) your tool doesn't have? I went with "say so explicitly." Curious whether there's a better pattern.
Top comments (0)