PNG or GIF?

Which one should you use? In a nut­shell, PNG, except in some sce­nar­ios. Plus, a cou­ple of PNG optimizers.


In this tip we will explore the two main choices of graphic for­mat that can be used on the Web to rep­re­sent sim­ple graph­ics, schemas or logos:

  • GIF (stands for Graph­ics Inter­change For­mat) was devel­oped in the late 1980's and it is still widely used.
  • PNG (Portable Net­work Graph­ics) was devel­oped around 1995, became a W3C rec­om­men­da­tion in 1996, and has been widely imple­mented in most Web browsers as soon as 1998.

GIF

The GIF for­mat is a for­mat which com­presses files using an algo­rithm called LZW, which keep traces of the col­ors and helps to reduce the size of the file.

GIF's strong point is that it is very widely sup­ported and thus well estab­lished as the default choice for sim­ple graph­ics on the Web. Com­pared to the other choices (espe­cially PNG) GIF is not tech­ni­cally supe­rior, but dur­ing the first years of the Web, when sup­port for PNG was start­ing and grow­ing, it was indeed a safer choice, and prob­a­bly still is a safer choice.

One of the issues sur­round­ing the GIF for­mat is that the LZW algo­rithm was pro­tected in the USA by a patent held by the com­pany Unisys. The Unisys LZW patent expired in the USA on June 20, 2003. LZW patents are expired in Canada, France, Italy, Ger­many, the United King­dom, and Japan.

PNG

PNG (Portable Net­work Graph­ics), an exten­si­ble file for­mat for the loss­less, portable, well-compressed stor­age of raster images. PNG pro­vides a patent-free replace­ment for GIF and can also replace many com­mon uses of TIFF. Indexed-color, grayscale, and true­color images are sup­ported, plus an optional alpha chan­nel. Sam­ple depths range from 1 to 16 bits.

For the Web, PNG really has three main advan­tages over GIF:

  • alpha chan­nels (vari­able transparency),
  • cross-platform gamma cor­rec­tion (con­trol of image bright­ness) and color correction
  • two-dimensional inter­lac­ing (a method of pro­gres­sive display).

PNG also com­presses bet­ter than GIF in almost every case (5% to 25% in typ­i­cal cases).

Though in some cases, it's impor­tant to notice that PNG could have a bad sup­port by old browsers or spe­cific fea­tures like trans­parency. To be more informed on the level of sup­port of PNG in dif­fer­ent browsers, you should read:

Fur­ther Reading

1 comment
  1. Garcia says: Jul 08, 20051:43 pm

    Browser sup­port for PNG is excel­lent in every browser except for IE/Windows, which to this day refuses to sup­port alpha trans­parency in PNG images. You can always work around this prob­lem though, espe­cially if you're using CSS, like so:

    #header {
    background-image: url('/images/notgood.gif');
    }
    body > #header {
    background-image: url('/images/better.png');
    }

    That code above will show the PNG to every browser that sup­ports CSS2 (which right now is all of them except for IE/Windows).

    That said, GIF still has its place. If you want sim­ple ani­mated graph­ics with­out resort­ing to Flash then it's your only other choice (there are ani­mated PNGs, called MNGs, but browser sup­port is abysmal). Use what you want, but be aware of each format's lim­i­ta­tions and work around it accordingly.

    I use PNG on some sites myself, and find myself using it more and more, but for the most part I stick to GIF or Jpeg.

Submit comment