What are the different usecases of PNG vs. GIF vs. JPEG vs. SVG?

后端 未结 13 1788
無奈伤痛
無奈伤痛 2020-11-22 11:28

When should certain image file types be used when building websites or interfaces, etc?

What are their points of strength and weakness?

I know that PNG &

相关标签:
13条回答
  • 2020-11-22 12:02

    As pointed out by @aarjithn, that WebP is a codec for storing photographs.

    This is also a codec to store animations (animated image sequence). As of 2020, most mainstream browsers has out of the box support for it (compatibility table). Note for WIC a plugin is available.

    It has advantages over GIF because it is based on a video codec VP8 and has a broader color range than GIF, where GIF limits to 256 colors it expands it to 224 = 16777216 colors, still saving significant amount of space.

    0 讨论(0)
  • 2020-11-22 12:06

    GIF is limited to 256 colors and do not support real transparency. You should use PNG instead of GIF because it offers better compression and features. PNG is great for small and simple images like logos, icons, etc.

    JPEG has better compression with complex images like photos.

    0 讨论(0)
  • 2020-11-22 12:11

    JPEG will have poor quality around sharp edges etc. and for this reason it is unsuitable for most web graphics. It excels at photographs.

    Compared to GIF, PNG offers better compression, larger pallette and more features, including transparency. And it is lossless.

    0 讨论(0)
  • 2020-11-22 12:11

    png has a wider color pallete than gif and gif is properitary while png is not. gif can do animations, what normal-png cannot. png-transparency is only supported by browser roughly more recent than IE6, but there is a Javascript fix for that problem. Both support alpha transparency. In general I would say that you should use png for most webgraphics while using jpeg for photos, screenshots, or similiar because png compression does not work too good on thoose.

    0 讨论(0)
  • 2020-11-22 12:15

    JPEG is not the lightest for all kinds of images(or even most). Corners and straight lines and plain "fills"(blocks of solid color) will appear blurry or have artifacts in them depending on the compression level. It is a lossy format, and works best for photographs where you can't see artifacts clearly. Straight lines(such as in drawings and comics and such) compress very nicely in PNG and it's lossless. GIF should only be used when you want transparency to work in IE6 or you want animation. GIF only supports a 256 color pallete but is also lossless.

    So basically here is a way to decide the image format:

    • GIF if needs animation or transparency that works on IE6(note, PNG transparency works after IE6)
    • JPEG if the image is a photograph.
    • PNG if straight lines as in a comic or other drawing or if a wide color range is needed with transparency(and IE6 is not a factor)

    And as commented, if you are unsure of what would qualify, try each format with different compression ratios and weigh the quality and size of the picture and choose which one you think is best. I am only giving rules of thumb.

    0 讨论(0)
  • 2020-11-22 12:16

    There is a hack that can be done to use GIF images to show true color. One can prepare a GIF animation with 256 color paletted frames with 0 frame delay and set the animation to be shown only once. So, all frames could be shown at the same time. At the end, a true colored GIF image is rendered.

    Many software is capable of preparing such GIF images. However, the output file size is larger than a PNG file. It must be used if it is really necessary.

    Edit: As @mwfarnley mentioned, there might be hiccups. Still, there are still possible workarounds. One may see a working example here. The final rendered image looks like that:

    full-color-gif-image

    0 讨论(0)
提交回复
热议问题