Formats, Metadata and Vector Graphics

Metadata

The pixels of an image are its data. An image may also contain some metadata, meaning data that describes a file's data, such as the width, the height, the size and the location of the image.
Metadata allow data to be structured and organized.
Metadata are used for finding, organizing and managing information. Metadata can increase the effective use of data or data sets by providing additional information about various aspects of that data.

Comparing four formats

Like GIF, PNG uses lossless compression, and like JPEG, PNG uses 24 bits for colour.
Another feature of the PNG format is support for alpha, or transparency. An alpha channel stores a see-through level for every pixel, from fully transparent to fully solid. BMP and JPEG, on the other hand, don't have a channel devoted to transparency. GIF has no alpha channel either, but it can mark one colour as transparent, so each of its pixels is either fully shown or fully hidden.
GIF does have the distinct advantage of supporting animation, achieved by repeatedly showing a series of frames.
Here is a summary of these formats. The alpha channel is one reason .png files are popular in game images (Sprites).
NameExtensionCompressionColourAlpha
Bitmap.bmpNo24-bitNo
GIF.gifLossless8-bitNo (one transparent colour)
JPEG.jpg, .jpegLossy24-bitNo
PNG.pngLossless24-bitYes
A soft-edged spot over a checkered background, shown twice. PNG: the blue spot fades smoothly into the checkerboard at its edge. An alpha channel: each pixel has its own see-through level, so the edge fades out. GIF: the spot has a hard, stepped edge with the checkerboard fully visible around it. One colour marked see-through: each pixel is either fully shown or fully hidden.

Vector Graphics

If a raster graphics image is scaled larger, the image will appear pixelated. The file stores only the pixels it was saved with. Scaling it up can only stretch those pixels, into bigger squares or a blur, and no new detail appears. Vector graphics can scale without losing quality.
Unlike raster graphics, vector graphics doesn't involve turning an image into a grid and storing the values of individual pixels. Instead, vector graphics stores images using mathematics.
The program below draws a circle from its rule, and the one number it keeps is r. It works through the rows and columns from -r to r. It prints a # wherever x squared plus y squared is at most r squared, which fills in the circle. Run it, then change it and run it again:
• Change r to 8. Every pixel is worked out again from the rule, so the larger circle is not the small one stretched.
• Change r to 2. Five pixels across are too few to show the curve.
let r = 4;
for (let y = -r; y <= r; y++) {
  let line = "";
  for (let x = -r; x <= r; x++) {
    if (x * x + y * y <= r * r) {
      line = line + "# ";
    } else {
      line = line + ". ";
    }
  }
  console.log(line);
}
Output
Press Run to see what this program prints.

Note: This IDE is for experimenting with the code in this lesson. Your changes are not saved, and refreshing the page puts back the original lesson code.

Scalable Vector Graphics

Scalable Vector Graphics (SVG) is an example of a vector graphic.
The figure below stores one heart both ways and enlarges each copy 8 times. The raster copy breaks up into visible squares along every curve. The vector copy is drawn again from its description at the new size, so it comes out as clean as it was before.
One heart, stored two ways, enlarged 8 times. Each side shows a small original and the enlarged copy. Raster: 20 by 20 pixels. Enlarging repeats each pixel as an 8 by 8 block of one colour, so the heart's edge is a staircase of squares. Vector: a rule for the outline. Enlarging redraws the shape from the rule at the new size, so the edge stays a smooth curve.