views:

2040

answers:

21

When doing small icons, header graphics and the like for websites, is it better to use GIFs or PNGs?

Obviously if transparency effects are required, then PNGs are definitely the way to go, and for larger, more photographic images I'd use JPEGs - but for normal web "furniture", which would you recommend and why? It may just be the tools I'm using, but GIF files usually seem to be a bit smaller than a comparible PNG, but using them just seems so 1987.

A: 

I use jpg for all non-transparent images. You can control the compression, which I like. I found this web site that compares the two. jpg is smaller and looks better.

dbrien
JPEG compression only makes sense with photo-like pictures. Many pictures don't profit at all from JPEG compression, which is lossy, and can be made smaller by the (always lossless) PNG compression.
Konrad Rudolph
Oops. Thanks for pointing this out.
dbrien
A: 

Personally I use gif's quite a bit for my images, as they work everywhere, obviously your transparency limitation is one key element that would direct someone towards a specific format.

I don't see any downfalls to using gif's.

Mitchel Sellers
Downfalls to using Gifs? They can be bigger, they have a limited palette, and a very limited transparency scheme.
PhiLho
A: 

If they get smaller and you have nothing to gain from using the features PNG offers (which is alpha channel transparency and more than 256 colors) then I see no reason why you should use PNG.

kigurai
+4  A: 

The main reason to use PNG over GIF from a legal standpoint is covered here:

http://www.cloanto.com/users/mcb/19950127giflzw.html

The patents have apparently expired as of 2004, but the idea that you can use PNG as open-source over GIF is appealing to many people.

(png open source reference: http://www.linuxtoday.com/news_story.php3?ltsn=1999-09-09-021-04-PS)

devinmoore
even the FSF and GNU project use some GIF's on their websites. the GIF patent issue is dead.
Corey Goldberg
+2  A: 

I don't think it makes a lot of difference (customers don't care). Personally I would choose PNGs because they are a W3C standard.

Be cautious with the PNG transparency effects: they don't work with IE6.

Christoph Schiessl
Not true for IE6 limitation. There are workarounds, and 8bit PNG need no tricks to work there.
PhiLho
+47  A: 

As a general rule, PNG is never worse, and often better than GIF because of superior compression. There might be some edge cases where GIF is slightly better (because the PNG format may have a slightly larger overhead from metadata) but it's really not worth the worry.

It may just be the tools I'm using, but GIF files usually seem to be a bit smaller than a comparible PNG

That may indeed be due to the encoding tool you use.

/EDIT: Wow, there seem to be a lot of misconceptions about PNG file size. To quote Matt:

There's nothing wrong with GIFs for images with few colours, and as you have noticed they tend to be smaller.

This is a typical encoding mistake and not inherent in the format. You can control the colour depth and make the PNG file as small. Please refer to the relevant section in the Wikipedia article.

Also, lacking support in MSIE6 is blown out of proportion by Chrono:

If you need transparency and can get by with GIFs, then I'd recommend them because IE6 supports them. IE6 doesn't do well with transparent PNGs.

That's wrong. MSIE6 does support PNG transparency. It doesn't support the alpha channel (without a few hacks), though but this is a different matter since GIFs don't have it at all.

The only technical reason to use GIFs instead of PNGs is when use need animation and don't want to rely on other formats.

Konrad Rudolph
Thanks for the detailed answer - I have often wondered this myself, especially the "lack of PNG support in IE."
Chris Marasti-Georg
With regards to file sizes and encoding tools, I highly recommend PNGOUT (http://advsys.net/ken/utils.htm) to compress PNG files.
Bradley Grainger
Great answer - but your last sentence appears to be missing a word. Wish I could edit it for ya...
Cory House
The other technical reason is you want alpha channel.
recursive
A: 

If you need transparency and can get by with GIFs, then I'd recommend them because IE6 supports them. IE6 doesn't do well with transparent PNGs. But if you don't need IE6 support, I'd go with PNGs. For solid color backgrounds, I like to use PNGs as I can get better color reproduction.

ChronoPositron
+1  A: 

A major problem with GIFs are that it is a patent-encumbered format (EDIT: This is apparently no longer true). If you don't care about that, feel free to use GIFs. PNGs have a lot more flexibility over GIFs, particularly in the area of colorspace, but that flexibility often means you'll want to "optimize" the PNGs before publishing them. A web search should uncover tools for your platform for this.

Of course, if you want animation, GIF is the only way to go, since MNG was basically a non-starter for some reason.

foxxtrot
Unisys' GIF patent (US 4,558,302) expired in June 2003
stevenvh
A: 

gif files will tend to be a little smaller since they don't support a transparency alpha channel (and maybe for some other reasons). Personally, I don't feel the size difference is really worth worrying about nearly as much as it used to. Most people are using the web with some sort of broadband now, so I doubt they will notice a difference.

It's probably more important to use the type of images that your manipulation tools work best with.

Plus, I like the ability to put an image on any background and have a drop shadow work, which points me more towards the png format.

anopres
Your first sentence is probably a reason that the average GIF file is smaller than the average PNG file, but you need to compare like with like for it to be relevant to the question.
Stewart
+11  A: 

The W3C mention 3 advantages of PNG over GIF.

• Alpha channels (variable transparency),

• Cross-platform gamma correction (control of image brightness) and color correction

• Two-dimensional interlacing (a method of progressive display).

Also, have a look at these resources for guidance:

Leo Moore
A: 

I usually use gif's because of the size, but there is also png-8 which is 256 colours as well.

If you need fancy semi-transparent stuff then use png-24.

I usually use the 'save for web' feature in photoshop, which lets you fiddle with filetype, number of colours etc and see the result before you save. Of course I would use the smallest possible which still looks good in my eyes.

mrinject
A: 

For computer generated graphics (i.e. drawn by yourself in Photoshop, Gimp, etc.) JPG is out of the question, because it is lossy - i.e. you get random gray pixels. For static images, PNG is better in every way: more colors, scalable transparency (say, 10% transparent, .gif only supports 0% and 100%), but there is a problem that some versions of Internet Explorer don't do PNG transparency correctly, so you get flat non-transparent background that looks ugly. If you don't care about those IE users, go for PNG.

BTW, if you want animations, go for GIF.

Milan Babuškov
+2  A: 

For images on the web, each format has its pros and cons. For photograph-type images (ie lots and lots of colours, no hard edges) use a JPEG.

For icons and the like, you have a choice between PNG and GIF. GIFs are limited to 256 colours. PNGs can be formatted like GIFs (ie 256 colours, with 1-bit transparency that will work in IE6), but for small images they're slightly larger than GIFs. 24-bit PNGs support both a large gamut, and alpha transparency (although it's troublesome in IE6).

PNGS are your only really sensible choice for things like screenshots (ie, both lots of colours and hard edges), and personally, that's what I stick with most of the time, unless I have something for which JPEG is more suitable (like a photo).

Dan
A: 

I always use GIFs. If I have an image that is only black and white then I have the option to save my GIF as a 2 bit color image with the colors black and white. This saves image size and loading time on my websites. Remember not every one has high speed internet and you want your page to load as fast as possible.

Of course there are some downsides to the amount of quality that you can have in a GIF. For images that are larger, like header graphics, and require a larger color range for crisper color quality I always use JPEG.

Dustin
A png can also do the 2 color thing
Albert
A: 

Burn All Gifs!!!!

axel_c
+6  A: 

Wow, I'm really suprised with all the wrong answers here. PNG-8 will always be smaller than GIF when properly optimized. Just run your PNG-8 files through PngCrush or any of the other PNG optimization routines.

The key things to understand:

  • PNG8 and GIF are lossless <= 256 colors
  • PNG8 can always be smaller than GIF
  • GIF should never be used unless you need animation

and of course,

  • Use JPG for black&white or full color photographic images
  • Use PNG for low color, line art, screenshot type images
JarrettV
It's worth pointing out that a 16x16 or smaller image will always have 256 colors or less, because it only has 256 pixels or less!
Mark Ransom
A: 

Indexed PNG (less than 256 colors) is actually always smaller than gif, so I use that most of the time.

Phrodo_00
+1  A: 

PNG is a 100% replacement for GIF files and is supported by all web browsers you are likely to encounter.

There are very, very few situations where GIF would be preferable. The most important one is animation--the GIF89a standard supports animation, and virtually every browser supports it, but the plain old PNG format does not--you would need to use MNG for that, which has limited browser support.

Virtually all browsers support single-bit transparency in PNG files (the type of transparency offered by the GIF format). There is a lack of support in IE6 for PNG's full 8-bit transparency, but that can be rectified for most situations by a little CSS magic.

If your PNG files are coming out larger than equivalent GIF files, it is almost certainly because your source image has more than 256 colors. GIF files are indexed to a maximum palette of 256 colors, while PNG files in most graphics programs are saved by default in a 24-bit lossless format. If file size is more important than accurate colors, save the file as an 8-bit indexed PNG and it should be equivalent to GIF or better.

It is possible to "hack" a GIF file to have more than 256 colors using a combination of animation frames with do-not-replace flags and multiple palettes, but this approach has been virtually forgotten about since the advent of PNG.

richardtallent
+2  A: 

Be careful of color shifts when using PNG. This link gives an example, and contains many more links with further explanation:

http://www.hanselman.com/blog/GammaCorrectionAndColorCorrectionPNGIsStillTooHard.aspx

GIF images are not subject to this problem.

Mark Ransom
The basic IE bug with PNGs is that it gamma-corrects to the wrong target gamma. The only reason that GIFs aren't subject to it is that GIF doesn't provide a way to specify the gamma.To get around it, get your graphics app to save PNGs without gamma. See alsohttp://www.libpng.org/pub/png/png-gammatest.html
Stewart
This link http://hsivonen.iki.fi/png-gamma/ explains that PNGs without gamma will still display incorrectly in some browsers. Perhaps those browsers are obsolete enough that you don't need to worry about them, but everyone should at least be aware of the issue.
Mark Ransom
I can imagine that some browsers on non-Windows platforms with gamma adjustment in the hardware and/or OS might adjust CSS colours to sRGB per its spec, but leave PNGs with no colour space info unadjusted. As such, specifying sRGB in the PNG ought to do it, but I've just found that Firefox then does its own thing for some reason I can't imagine....
Stewart
A: 

Use smushit.com (also as Firefox extension available) to get the best out of your image files.

Gumbo
A: 

"It may just be the tools I'm using, but GIF files usually seem to be a bit smaller than a comparible PNG, but using them just seems so 1987."

It probably is your tools. From the PNG FAQ:

"There are two main reasons behind this phenomenon: comparing apples and oranges (that is, not comparing the same image types), and using bad tools." continued...

But you could always try saving as both (using the same colour depth) and see which comes out smaller.

Of course, if you want to standardise on one graphic format for your site, PNG is likely to be the best one to use.

Stewart