Menu

Checking an image against platform specs in the browser, without uploading it
📰

Checking an image against platform specs in the browser, without uploading it

DEV Community: typescript·Alan·4 days ago
#Mn4bUV92
#devtotypescript#devto#dev#file#const
Reading 0:00
15s threshold

A 2.3 MB thumbnail is inside YouTube's limit when you upload it from a computer and over it when you upload from the mobile app. YouTube allows 50 MB from a computer and 2 MB from the app, so the same file passes in one place and not in the other.

Most of what makes an image wrong for a platform can be read from the file itself: pixel size, aspect ratio, byte size, file type, transparency and, for marketplace photos, how white the background is. We built a checker for this in PiCraft (picraft.ai). It runs entirely in the browser and nothing is uploaded. This post covers how it reads each of those things, and where it is only estimating.

What the checker needs from a file

Six values:

Width and height in pixels

Size in bytes

File type

Share of transparent pixels

Share of the border that is pure white

How much of the frame the non-white content spans

The first three are read from the file.…

Continue reading — create a free account

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