applets.

Picture Squeezer

← All apps

About Picture Squeezer

A photo, once the camera has worked out each pixel's colour, holds three numbers for every pixel, red, green and blue, one byte each: a 12-megapixel photo is 36 MB. Phones save it as a JPEG (or a newer format built on the same ideas) of a few megabytes, and it looks the same. This page does what the phone does, step by step, on pictures you can look at closely, and shows what was thrown away.

SQUEEZE: pick a picture (or open one of your own) and slide the quality. The page really makes the JPEG file, byte for byte, and shows its size and the picture a JPEG decoder rebuilds from it. Drag the line to wipe between the original and the squeezed copy, or show either on its own; DIFFERENCE shows what changed, made six times brighter. The two loupes enlarge the same spot of both, with the 8 × 8 blocks marked: move the mouse over the picture to move them, click to keep the spottap the picture to move them. SAVE .JPG gives you the file itself.

THE 64 WAVES: every 8 × 8 block is rebuilt as a sum of 64 fixed patterns, from flat (the block's average) to the finest checkerboard. Pick a block, then add the patterns one at a time in the zigzag order a JPEG stores them. The numbers are each pattern's strength after rounding at your quality: most are 0, and that is where the saving comes from.

COLOUR: the picture split into brightness (Y) and two colour differences (Cb, blue against yellow, and Cr, red against blue-green). The two large panels are close-ups of the same spot: on the left the colour is shrunk, on the right the brightness is, by the colour setting chosen (to a quarter at 4:2:0, to half at 4:2:2; at 4:4:4 nothing is shrunk and both match the original). In most photos shrunk colour is hard to see, and shrunk brightness looks blurred.

SAVE AGAIN: the squeezed picture opened and saved again, and again. With the same quality and nothing moved, most of the damage happens on the first save. Change the quality each time, or move the picture by a pixel (as cropping does), and it keeps wearing down.

THE STORY

The Joint Photographic Experts Group, set up in 1986 by the international standards bodies ISO and the CCITT (now ITU-T), chose its method by testing proposals on real pictures and real viewers. The standard was approved by the ITU-T in 1992 as Recommendation T.81, and by ISO as standard 10918-1 soon after. The file layout nearly everyone uses, JFIF, was written by Eric Hamilton at C-Cube Microsystems, and the free code of the Independent JPEG Group, first released in 1991, put JPEG into browsers, cameras and phones. Its quality scale from 1 to 100 is the one this page uses; the standard itself has no such scale.

The heart of it, the discrete cosine transform, came from Nasir Ahmed. In 1972 he asked the US National Science Foundation for money to study it for compressing pictures, and was turned down: by his own account, one reviewer thought the idea too simple. He worked it out anyway with T. Natarajan and K. R. Rao, and they published it in January 1974. The same transform, with small changes, is in MP3 and AAC sound and in the video formats that came after JPEG.

HOW IT WORKS

1. Each pixel's red, green and blue become Y = 0.299 R + 0.587 G + 0.114 B, and two colour differences, Cb and Cr (the JFIF formulas). 2. Cb and Cr are averaged over 2 × 1 pixels (4:2:2) or 2 × 2 (4:2:0), or kept whole (4:4:4). 3. Each plane is cut into 8 × 8 blocks and each block is turned into the strengths of 64 cosine patterns. Nothing is lost yet. 4. Each strength is divided by a number from a table and rounded to a whole number. The tables are the examples printed in the standard (Annex K), with big numbers for fine patterns, which the eye notices least; the quality setting scales them with the Independent JPEG Group's formula (quality 50 uses them as printed, 100 makes every number 1, 75 halves them). 5. The rounded numbers are read in zigzag order, from coarse to fine, so the zeros come in long runs; each block's average is stored as the change from the last block; then each run and number gets a Huffman code from the standard's example tables. The page writes all of this into a real .jpg file, with the headers a decoder needs, and the size shown is that file's size (1 KB = 1,024 bytes).

To rebuild the picture the page multiplies the rounded numbers back up, adds the patterns, stretches the colour back with a straight-line blend between neighbours, and converts to red, green and blue, as a decoder does. Rounding (step 4) and averaging the colour (step 2) are where nearly everything is lost. Rebuilding adds a little more: each value is rounded to a whole number again, and anything outside 0 to 255 is cut off.

SIMPLIFICATIONS

Real encoders are cleverer than this one. Many phones and cameras use their own tables rather than the standard's examples, many work out Huffman codes to suit each picture (a few per cent smaller), and some use progressive JPEG or newer formats such as HEIF; so your browser's own JPEG of the same picture, shown for comparison, can differ in size, most of all at the top qualities. The DCT here is done in exact floating-point sums, where real coders use fast integer versions; the results differ by a pixel value now and then. The size of a photo you open is its size after this page has drawn it at most 1,200 by 900 pixels, without the camera's details (EXIF) a real file carries. Your pictures never leave this tab and nothing is kept.

FURTHER WATCHING AND READING