Preloader
Others
  • Estimated reading time: 5 Minutes

Lint Your Product Photos Like Code: Python Preflight Check for Amazon & Shopify

Lint Your Product Photos Like Code: Python Preflight Check for Amazon & Shopify

You upload a batch of product photos to Amazon and a few listings bounce. The main images look white, but the color picker reads RGB(246, 247, 245) because the studio wall was slightly underexposed. No eye catches that.

Most rejections come down to things you can measure, like background color, pixel count, how much of the frame the product fills, and file format and size. So I lint product images like code. Every image runs through a Python check before upload, and only the failures go to retouching.

Write the Platform Rules as Config

For the main image, Amazon Seller Central requires a pure white background, RGB(255, 255, 255), with the product filling about 85% of the frame. Zoom on the detail page needs a long side of at least 1000px. Images from 500 to 999px will upload, but shoppers can’t zoom in. Text, logos and watermarks aren’t allowed either, and a person still has to check for those.

Shopify has no background rule, so its config is a performance check. Both rule sets go into one dict, or a YAML file loaded with yaml.safe_load:

import sys
from pathlib import Path

import numpy as np
from PIL import Image

RULES = {
    "amazon_main": {
        "formats": {"JPEG", "PNG", "TIFF", "GIF"},
        "min_long_edge": 1000,
        "white_bg": True,
        "fill_range": (0.80, 0.92),
        "max_bytes": 2_000_000,
    },
    "shopify": {
        "formats": {"JPEG", "PNG", "WEBP"},
        "min_long_edge": 2048,
        "white_bg": False,
        "fill_range": None,
        "max_bytes": 500_000,
    },
}

The max_bytes values are budgets my team picked, not platform limits. Shopify’s 2048px comes from its Help Center recommendation for square product images. Amazon recommends 2000×2000 and accepts 1000px as the minimum. It also rejects a long side over 10,000px, so raw camera files can fail too. Raise min_long_edge to 2000 if you want sharper zoom.

The Four Checks

def lint_image(path, rule):
    problems = []
    img = Image.open(path)

    if img.format not in rule["formats"]:
        problems.append(("error", f"format {img.format} not allowed", "format"))

    size = Path(path).stat().st_size
    if size > rule["max_bytes"]:
        problems.append(("warn", f"{size // 1000} KB > {rule['max_bytes'] // 1000} KB budget", "file-size"))

    width, height = img.size
    if max(width, height) < rule["min_long_edge"]:
        problems.append(("error", f"long edge {max(width, height)}px < {rule['min_long_edge']}px", "resolution"))

    pixels = np.asarray(img.convert("RGB"))

    if rule["white_bg"]:
        edges = np.concatenate([pixels[0], pixels[-1], pixels[:, 0], pixels[:, -1]])
        off_white = np.any(edges < 255, axis=1).mean()
        if off_white > 0:
            problems.append(("error", f"{off_white:.1%} of edge pixels are not RGB 255", "white-bg"))

    if rule["fill_range"]:
        ys, xs = np.nonzero(np.any(pixels < 250, axis=2))
        low, high = rule["fill_range"]
        if xs.size == 0:
            problems.append(("error", "no product found", "fill-ratio"))
        else:
            fill = max((xs.max() - xs.min() + 1) / width, (ys.max() - ys.min() + 1) / height)
            if not low <= fill <= high:
                problems.append(("warn", f"fill {fill:.2f}, expected {low}-{high}", "fill-ratio"))

    return problems


def main(platform, paths):
    rule = RULES[platform]
    failed, has_error = 0, False
    for path in paths:
        problems = lint_image(path, rule)
        if not problems:
            continue
        failed += 1
        print(path)
        for level, message, rule_id in problems:
            has_error |= level == "error"
            print(f"  {level:<6} {message:<44} {rule_id}")
    print(f"\n{failed} of {len(paths)} images need fixing")
    return 1 if has_error else 0


if __name__ == "__main__":
    sys.exit(main(sys.argv[1], sys.argv[2:]))

The background check reads every edge pixel, not just the corners, so a shadow or product touching the frame still gets caught.

For fill, the script boxes every pixel with a channel below 250 and keeps the larger of the two box-to-image ratios. The 250 threshold stops JPEG noise from stretching the box, but pale shadows get counted too, hence 0.80 to 0.92 instead of exactly 85%. The script ignores PNG transparency, which can turn black in the RGB conversion, since an Amazon main image should be solid white anyway.

The Report

Run python preflight.py amazon_main photos/*.jpg:

photos/mug-blue-01.jpg
  error  4.3% of edge pixels are not RGB 255           white-bg
  warn   fill 0.71, expected 0.8-0.92                   fill-ratio
photos/mug-blue-02.jpg
  error  long edge 880px < 1000px                      resolution

2 of 24 images need fixing

Any error makes the script exit with code 1, so it drops straight into a pre-commit hook or GitHub Actions. Designers find out which images fall short when they commit to the asset repo, not when the platform reviews them.

Don’t ignore the file-size warn either. LCP (Largest Contentful Paint) measures how long the largest above-the-fold element takes to render. The performance chapter of HTTP Archive’s Web Almanac 2025 reports that this element is an image on about 76% of mobile pages. Of those images, about 57% are JPG, 11% are WebP and 0.7% are AVIF, and about 16% of pages lazy-load them. Only about 62% of mobile pages pass LCP, the lowest rate of the three Core Web Vitals. On a product page, the hero image is almost always the LCP element.

Fixing the Images That Fail

Resolution, format and file size are easy. In the same script, img.thumbnail() resizes and img.save(out, "WEBP", quality=82) converts the format. Upscaling a too-small image won’t help, so go back to the original or reshoot. For a one-off resize, someone on the ops team can use a free online image resizer and drop the result back in the asset folder for the next run.

Background and fill are harder. Homemade cutout code chokes on stray hairs, clear bottles and the contact shadow under a product, and a small threshold change leaves a white or gray halo. I’d rather hand this to a tool that outputs white backgrounds directly. Upload a photo to Snappyit’s Product Studio, leave the extra details blank, and you get back a packshot with even lighting and a natural contact shadow.

Lint the generated images too. AI white backgrounds often miss RGB 255 by a few values at the edges, and the white-bg rule will flag them. Push the edge pixels to 255 in one pass or regenerate, then rerun until the report shows zero errors. That way a background a few values off gets caught on your own machine, before Amazon bounces the main image.

Related articles
How to Build Reliable Software Integrations Across Different Systems
18 Nov, 2026
  • Estimated reading time: 7 Minutes
Selecting the Right Audio Companion: A Guide to Buying Speakers
18 Nov, 2026
  • Estimated reading time: 4 Minutes
How IPTV Streaming Works: HLS, Codecs, EPG Data & Home Network
18 Nov, 2026
  • Estimated reading time: 4 Minutes
Why Office Walls Are Your Most Overlooked Marketing Asset
18 Nov, 2026
  • Estimated reading time: 4 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.