JPEG/GIF/PNG – When to use each Format
Posted by Jon Lee in Web Development, tags: GIF, images, JPEG, PNG, tips, web developmentI get frustrated when people send me screenshots of their desktop saved as a bitmap file (.bmp) because they don’t know how (or are too lazy) to change the image format. Bitmaps are uncompressed. This means a 1024 by 768 pixel image (XGA) can have a file size of over 2 megabytes. I don’t want to wait 3 minutes to see a picture of your new icon layout nor would you want your readers to wait 3 minutes for your page to load!
Enter the world of compressed images. This article isn’t going to go into the technical details of how image compression algorithms work (I had to write an algorithm in University, I’ll spare you the linear algebra lesson). I will briefly describe the three most popular formats and situations in which you should use them.
JPEG (Joint Photographic Experts Group)
JPEG images use a lossy compression algorithm meaning that some information is loss every time you save (or resave) an image in the JPEG format. Upon saving, you usually get a choice of what JPEG quality you wish to save at. Medium should be fine for web development; this is essentially a trade-off between file size and image quality. JPEGs are a good choice for anything that contains a lot of color information and detail — basically any photograph or anything containing a photograph (like the name implies).

GIF (Graphical Interchange Format)
GIF images use a lossless algorithm meaning no information is lost in your image; instead, your image is compressed by using an index of colors. For this reason, GIFs are best used in images that have limited colors. Since GIFs don’t lose any information (assuming there are enough colors), you won’t get the problem of blurred sharp edges you get with JPEGs. So any sort of computer/web graphic should be saved as a GIF file. GIFs also support animation and basic transparency.

PNG (Portable Network Graphic)
PNGs are the “new” cool thing. They were created as a free version of GIF (software that use the GIF format require a license). Like GIFs, PNGs are also lossless, support transparency and are best used with computer/web graphics. In addition, they also have true color, full alpha channel and gamma storage support. They’re pretty much better than GIFs in every aspect, so why don’t we use them exclusively?
- No support from older browsers — this may or may not be a concern for you depending on your target audience.
- Partial support from modern browsers (this is mainly an IE issue, but there are ways to get around it).
- No animation support.
Conclusion
In short (and for those too lazy to read the above), use JPEGs for photographs and GIF/PNGs for sharp-edged web graphics.
For the curious, here is a good site describing what I’ve talked above in more detail.
Popularity: 5% [?]
Entries (RSS)
Seriously . . . great post! I’ve always wondered and never took the time to learn the differences!
Funny story… I saw one of your screenshots on your blog saved as a JPEG, which was what inspired me to write this article!
That was a great post! I’ve always defaulted to saving as JPEG but never knew why. Now, I’ll think whether to save as JPEG or GIF. Thanks!
You don’t mention that PNG for non-transparent images works perfectly for the most part in even older versions of Internet Explorer. For this reason I always use it for screenshots. Unfortunately Photoshop doesn’t compress PNG’s very well, but being a GIMP user, there are no problems.
I actually didn’t know that. I guess you can tell from the images that I use Photoshop because of the large PNG file size.
Old old browsers unfortunately have no PNG support whatsoever but what really ticks me off is IE7 has only partial support.
You can read about PNG support in browsers (it actually is more or less updated, even if it appears… old) at libpng.
In case you didn’t know there have been attempts to make animated PNG’s, such as MNG and APNG. Mozilla used to have MNG support, but they dropped it after it never caught on.
Jon, in your opinion, is Photoshop worth its $649 price tag? It seems that everybody has it, but I can’t believe they all paid that much. I’m using an old version of Paint Shop Pro, but it’s time I got something with better compression abilities. Any recommendations?
I get it almost free through an educational discount with my school board along with other software like Dreamweaver. If I had to pay regular price, I definitely wouldn’t buy it. If you’re looking for something with good compression, I’d recommend The GIMP or even Paint.NET. Both free. Photoshop is really for those people that need CMYK support and other special features. I just use it because I can .. haha
[...] a previous article, I discussed different image formats and what situations call for each one. Many image editors offer a whole slew of features aside from just the format when you save an [...]
Thanks Jon. I’ll look into those.
[...] so sorry that even after reading Jon Lee’s wonderful post on JPEG/GIF/PNG, I’m still using JPEG for my pictures and making this blog hard to upload. I promise [...]
Great post. I’ve always preferred PNG myself, for non animated images. Specially for game screenshots, saving to JPG in paint seems to blur the colors together, but Photoshop seems to keep the quality.
I only use GIF for animated pictures and transparent pictures. I hate how IE makes the PNG colors darker or somehow changes the color. And also has trouble with PNG transparencies. Firefox ftw
I’ve been a fan of PNG for a while now but I’m as guilty as the next person about saving in JPG for almost everything.
Yea Microsoft’s refusal to properly support PNG alpha transparencies really ticks me off! Although you can use a Javascript hack to bypass it, Google htcbehavior
Oops, I meant pngbehavior.htc
Here’s the hack to make PNG transparencies work in IE:
http://webfx.eae.net/dhtml/pngbehavior/pngbehavior.html