Elements of image description: introduction
An image file is more than a list of pixel colors. To reproduce the picture, a program has to know how many pixels there are, what shape they are, how colors are stored, which are transparent, in what order the rows come and how it was all compressed. This part of the section covers these elements one by one.
Raster images
A raster image is a rectangular grid of points, pixels. Each pixel has one color. Image size is given in pixels, e.g. 1920 × 1080. A vector image (SVG, a PDF with graphics) describes shapes instead and can be enlarged without losing quality. This section is about raster images.
What a file describes
| Element | Question | More |
|---|---|---|
| dimensions | how many pixels across and down | |
| pixel aspect | whether a pixel is square | pixel aspect ratio |
| palette | whether colors are stored directly or as indices into a color table | color palette |
| color depth | how many bits per pixel or per component | color resolution |
| gamma and profile | how values relate to light and to colors | gamma correction |
| transparency | which pixels let the background through, and how much | transparency |
| row order | whether rows come in sequence or interlaced | interlacing |
| compression | how the data was reduced | LZW algorithm |
How much data an image takes
Uncompressed, an image takes width × height × bits per pixel:
Compression reduces that further. Lossless compression (LZW in GIF, Deflate in PNG) restores the data bit for bit. Lossy compression (JPEG, WebP, AVIF) removes detail the eye will not notice and can shrink a photo by a factor of tens.
Formats and their choices
| Format | Colors | Transparency | Compression |
|---|---|---|---|
| GIF | palette of up to 256 colors | one transparent color | LZW, lossless |
| PNG | palette or full color up to 16 bits per component | alpha channel | Deflate, lossless |
| JPEG | full color, 8 bits per component | none | DCT, lossy |
| WebP, AVIF | full color, AVIF also 10-12 bits | alpha channel | lossy or lossless |
The GIF format is described here in the most detail, byte by byte, in The GIF format step by step. It is simple, well documented and contains nearly every element in the table above.