Menu

Where to put an alpha-convention check in an image pipeline: at the resize call, not in the images
📰

Where to put an alpha-convention check in an image pipeline: at the resize call, not in the images

DEV Community: javascript·Lank_M·about 8 hours ago
#X0HNIC4V
#devtojavascript#devto#dev#sharp#alpha
Reading 0:00
15s threshold

The usual question about premultiplied alpha is which convention to pick. Mine is narrower: where do you put the check that tells you the convention you assumed is still the one being applied? I came at it from a small run on one cutout PNG, and the short answer is the resize call, not the stored images.

The input is a portrait photo from Wikimedia Commons (Dmitry Makeev, CC BY-SA 4.0), resized to 1330×2000. I ran it through the AI background removal in ImgIng, a browser tool at https://imging.ai/ , and exported a PNG. My part of that product is in-browser decoding and model loading, so this is about what I measured after the export. All portrait numbers are one image, one machine (Apple M4), one run, Chromium 149 and sharp 0.35.5.

Three libraries, three answers to the same resize

I shrank the cutout 4× and scaled it back up, then compared each result to two references written in numpy: one that scales R, G, B and A separately, and one that premultiplies first.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.