Image formats


The strength of PPM is that it is an easy format suitable to be chosen when you write a program and want to produce a file containing some pixel graphics. On the other hand it has absolutely not data compression, so the files become unnecessary big and it is not a file format the Microsoft Windows can easily deal (Gimp portable is a way).

PPM stands for portable pixmap picture. Those *.ppm files can be viewed or converted in other picture formats using external programs as convert<image>.ppm <image>.png from imagemagick. Portable pixmap can be ASCII or binary. For ASCII lines should not contain more than 70 * characters and therefore the ASCII format is quite limited.

The ASCII format starts with P3 in the first line. The # character can be inserted to have a comment line. The next line holds width and height separated by a blank character, then comes a line with a number that defines maximal of different steps per color. The following lines contain each a row of pixels, where 3 numbers set the rgb values for every pixel.

The binary format is similar but starts with ASCII P6 and CR The 2 following lines are identical to the ASCII format. The first line contains width and heights as ASCII characters. The second line contains a number that defines maximal color. Due to backward compatibility issues this value should not be greater than 255, to work with all kind of viewers and converters. With the next line the pixel data starts. With maximal color size smaller than 256 3 bytes for a pixel every byte holds a color (red, green, blue)

The project that created ppm is netpbm. It is a library and supports all kinds of features including command line tools to print text into a picture


Give is a popular image format that allows also animated pictures (a sequence of pictures). Unfortunately it has a license issue. Therefore certain developers care and exclude to implement gif support at least in their standard package. Optionally gif plugins are offered. Gentoo has a gif use flag to allow to be strict and exclude gif support. Because of this license issue it is good to avoid using gif and use a more GPL oriented picture format as png. Internet browsers and Microsoft should also support non gif pictures meanwhile.

To create animated gifs from individual gifs emerge gifsicle and run gifsicle --delay=10 --loop *.gif > anim.gif

More easy is using Gimp.


JPEG (Joint Photographic Experts Group) is a file format used for pixel graphics. When zooming in it can be seen that it is not suitable for vector graphics, since lines become zig zag-ed. When a picture is converted to JPEG then it looses some of its contents due to the data compression. However those losses are not really seen. Besides the picture JPEG allows to include other information about the picture.

For the data compression the following methods are used:

  1. The picture is first converted to a black and white picture (Y= luma) representing the brightness and a color picture containing just blue and red (chroma Cr & Cb). Green seems to be lost, however it can be reconstructed using the luma picture (YCrCb). The human eye (or brain) is more sensitive in the luma picture than the chroma picture. Therefore the resolution of the chroma picture can reduced, as you would scale it with width / 2 and height / 2. Therefore the chroma data is reduced to a quarter! A similar concept is also used in the PAL TV standard. Note this step can optionally be skipped within JPEG's.

  2. Next the pictures are segmented in 8*8 pixel blocks. Again the human eye (or brain) is not sensitive in frequent changes of colors and luminance over the short distance of 8 pixels. Therefore high frequent changes (luma and chroma) in the x and y axis of the 8*8 pixel block are filtered out. This is done by applying a DCT (Discrete Cosine Transformation) to the 8*8 pixel block and then damping the high frequent changes. DCT is a simpler less holistic variant of a Fourier transformation, requiring less calculation but similar results. (e.g. No phase angles are calculated, since they would have no big impact).

  3. Finally the picture can be compressed using a zipped algorithm (Huffman coding)

JPEG can hold various addition data that can be optional, as a preview picture and info about landscape or portrait. This meta data might be so complex that it might not be interpreted correctly for all kind of programs (on the PC it might look correctly, but on a multi media capable TV the orientation might be wrong).

To see what you have emerge jpeginfo. To get a library for jpeg emerge jpeg.

Modern cameras use metadata called exif so emerge exif. exif -l <name of picture>.jpg shows all the tags of your picture. exif can be used to manipulate the data. If this is still not possible use gimp and save the jpeg images without the exif data. Verify that the jpeg useflag is set.


SVG is a vector format, instead of having a picture with lots of pixels and telling what color they have, vector formats contain shapes as lines rectangular, circles, text and so on and describe how they look. This gives some advantages as no quality loss when zooming in and mostly the files are smaller than bitmaps. SVG is pure xml and can therefore easily be parsed, created modified and interact with software. Most web browsers understand it directly.

The svg root element has attributes width and height that define the viewport what to be seen it is possible to have units as cm. Note, the actual svg can be larger or smaller than the viewport (width and hight) to just show a fraction of the svg. The viewBox attribute allows translate the the svg inner coordinates to the ones set by the viewport (height and width). It has 4 parameters the first two allow to set an offset and the second two (width followed by height) scale the inner to the outer range.

Editors as inkscape, when doing something not that advanced amaya is an option

Linurs Servernest startpage