Anybody know at what compression level JPGs become more efficient (ie, smaller size) than 256-color GIFs? Is there some optimum compression level for JPGs that doesn’t force you to sacrifice quality on the altar of low bandwidth?
Thanks.
Anybody know at what compression level JPGs become more efficient (ie, smaller size) than 256-color GIFs? Is there some optimum compression level for JPGs that doesn’t force you to sacrifice quality on the altar of low bandwidth?
Thanks.
It depends on the image that you start with. Let’s say you had a JPEG composed of squares, like a chessboard or checkerboard, except that each square had a different color (RGB value) and that you had 800 squares.
By definition you can’t save it as a GIF without losing color information (you have more than 256 colors; something has to go). A JPEG file of that type would be a pretty small file since even I could readily create an algorithm for describing it efficiently [from pixel a1 to j10 inclusive: r=10102, b=23401, g=4676; etc].
At the GIFfy end of the spectrum of possibilities, let’s say you had something that looked somewhat more like an actual chessboard: two colors, red and green, on alternating squares, 100 squares total. At this point, a GIF file would be smaller and would contain the same information.
At the opposite end–the TIFFy end? – let’s say your total image size is 1024 x 768, OK? And not one single pixel has the same color as any other pixel, nor is there any mathematically discernable pattern (such as a linear or radial shading from one color to another) anywhere within the pattern. The JPEG format would not be able to improve on the cumbersome TIFF format without throwing away some color information: each would have to say “OK, now for the NEXT pixel, r=10102, b=23401, g=4676; then, moving right along to the NEXT pixel…”
In practice, JPEG compression is eerie in its ability to throw out information that your eye can’t distinguish and therefore you never see a JPEG turn up anywhere near as large as the same image was as a TIFF.
GIF images can be competitively small if there are only a few colors and simple patterns because it only has to save 8 bits of color informatin for each pixel, 1/3 as much info per pixel as a JPEG does.
In addition to the differences in color encoding for GIF and JPEG, there are differences in the compression of pixels that make them compress different types of images better/worse. As AHunter3 said, JPEG is very good for actual photographs and images of “real life” without a lot of edges. GIF is better for things like cartoons, line art, schematics, and “computer generated” graphics in general. The compression in GIF is designed to remove redunancies in pixels such as repeating patterns, and works well with lots edges. JPEG removes high frequency components to which the eye/brain isn’t sensitive. This usually means removing very fine details in textures, etc.- often unnoticeable. A JPEG-encoded blueprint wouldn’t work to well- edge line in the blueprint represents a lot of high-frequency energy in the image, whereas most pictures of real-life scenes don’t have a lot of hard edges (hence the difficulty of the “edge detection” problem when making algorithms to pick out objects in images).
Arjuna34
Thanks y’all.
I thought of the question as I was coding the index page of the zine I write for. I stuck in a nifty little random image javascript that selects from a directory of 200x150 and 150x200 pixel jpegs at the 16th compression level… mostly scanned photos and pics from a crappy 640x480 digital camera that I got for 50 bucks on eBay. Each jpeg was coming in at 9-11k, with some slightly ugly data loss, so I checked to see how they’d look at 256 colors. “Not bad,” I thought, and saved em as gifs. To my dismay, they then took up around 21k.
The reason I’m asking is that we plan to use a rather large number of images for the script, but we anticipate that the idjit punk rockers who read the zine will sit there and reload the mofo a few hundred times till they see a picture of themselves, which could cause bandwidth problems with the cheapo virtual domain host we’ll be moving to next month. Any advice would be appreciated.
Stick with jpeg for this. Don’t forget that if you save an image as a jpeg with some compression level, you don’t gain anything (except file size) by reloading it, then resaving it as GIF- the lossy compression from the jpeg has lost image detail forever. If you still have the original image, though, resaving as GIF might improve the quality (not the file size).
Arjuna34