What this is about
A picture on your screen is a grid of tiny colored dots called pixels. A 1344 by 768 picture has 1,032,192 of them. For each dot the computer must store a color. How the computer packs that long list of colors is what we mean by an image format. PNG, JPG, WebP and AVIF are four ways to pack the same grid.
Why it matters
A page with big pictures loads slowly, especially on a phone. A slow page loses readers. So you want the smallest file that still looks good. The format and the width you choose can change the file size a great deal, while the picture looks about the same.
How it works
Raw. Imagine storing each pixel's red, green and blue values as three numbers. That is simple and huge. The formats below are all smarter ways to write that grid down.
PNG: lossless. PNG finds patterns, such as a run of the same color, and writes them shorter. When you open it, you get back every pixel exactly. That is "lossless". It is perfect for screenshots, logos and anything with sharp edges. For photos or generated pictures it is large. Our originals were PNG at 1344 by 768 pixels and about 1.5 MB each.
JPG: lossy. JPG throws away detail your eye is unlikely to miss, mostly tiny color changes. That is "lossy". You choose a quality: lower quality, smaller file, more visible damage. JPG has been the standard for photos for a long time.
WebP and AVIF: newer lossy formats. They use smarter tricks and usually give a smaller file than JPG at the same look. AVIF is the newer of the two.
A quick guide:
| Format | Kind | Good for |
|---|---|---|
| PNG | lossless | logos, screenshots, sharp lines |
| JPG | lossy | photos, wide support |
| WebP | lossy or lossless | smaller than JPG, wide support |
| AVIF | lossy | smallest files for photos and generated art |
Also remember: you cannot get the lost detail back from a lossy file. Keep your originals.
What we measured
For the Romanian blog on doar.bio, we had 84 generated article pictures. As PNG at 1344 by 768, they came to 126.0 MB. Each also needed a logo band and a note that the picture is AI-generated.
Our script writes each picture as AVIF at quality 52 and as WebP at quality 80, at three widths: 480, 960 and 1344 pixels. Average size per picture:
| Format and width | Average size |
|---|---|
| Original PNG, 1344 px | 1,500 KB |
| Old WebP, 1200 px | 99 KB |
| New WebP, 960 px | 68 KB |
| New AVIF, 960 px | 36 KB |
| New AVIF, 480 px | 14 KB |
On a desktop, the 960 pixel AVIF replaces the old WebP: a drop of 64 percent. A phone 390 pixels wide loads the 480 pixel AVIF at 14 KB, which is 86 percent below the old 99 KB file.
One honest note. The full set at 1344 pixels is bigger: the 84 AVIF files at that width total 4.8 MB, or about 57 KB each. The 36 KB figure is for 960 pixels, and we show both because the lower figure alone would flatter us. And a page does not load the whole set. It picks one file per picture, depending on the screen width and what the browser accepts.
Two more things we did to keep it cheap: the script skips pictures it has already processed, by checking a hash of the source, the logo and the settings. A --check option confirms the output matches the settings.
What to learn from it
- Pick the width that fits the screen. A small phone does not need 1344 pixels.
- Pick a modern format and offer it, with a fallback for browsers that cannot open it.
- Keep the originals. Never overwrite them with a lossy copy.
- Measure the files you actually serve.
Image tools
We keep our own computer vision library, mojo-cv: it holds OpenCV-style 2D operations, calibration and 3D geometry, each checked against cv2. In one pass it decoded 406 mixed images in 10.9 seconds, down from 27.5 seconds, after we moved JPEG decoding into the same process.
Words you may meet
- Pixel: one dot of a picture.
- Lossless: no detail is lost when you save it.
- Lossy: some detail is thrown away to make the file smaller.
- Quality: a setting that trades size against visible damage.
- Width: how many pixels across the picture is.
- Hash: a short fingerprint of a file's content.
Try it
- Open any picture, and save it as PNG, then as JPG, then as WebP if your editor allows. Compare the sizes.
- Open doar.bio in your browser's developer tools, look at the Network tab and find the picture files. See which format and size you were served.
- Read the full story in Doar.bio article pictures in AVIF.
- Browse the library at github.com/amarbaro/mojo-cv.
What we do not claim
We measured only Chromium. We do not know how a real phone on a real network loads the page, and the 14 KB figure is a file size, not a page load.

Komentarze
Brak komentarzy.
Zaloguj się aby skomentować.