Here's a great illustration of why you should use PNG for line art rather than JPG:
![](http://lbrandy.com/blog/wp-content/uploads/2008/10/jpg_vs_png2.png)
After a discussion with a technical person who doesn't worry much about the details of image formats, I came away with this thought: There should be an image format, (maybe .image) that automatically packages things up in the right image format so regular people don't have to think about it. In terms of reading, it would just be a wrapper format for
PNG,
JPG, and
SVG. I think these three open standards pretty well cover all the images you might want to save.
If such an image format were to exist (does it?) that orthogonalizes the problem of smartly deciding how to save an image and actually storing the image. Storing is obviously trivial.
Saving is the interesting part, but it shouldn't be too difficult to do something that works pretty well.
If the image is vector graphics, store it as SVG. Done.
If the image has alpha blending in it, store it as PNG. Done.
Now for the fun part: JPG vs PNG. Given a compression level, ℓ a scalar between zero and 1.0, try saving the image as JPG at that compression level, try saving it as PNG. If the PNG is smaller, use it. Done.
Finally, we need to decide when it's OK to throw away data by using JPG. We could just measure JPG compression artifacts, so if we start with an image, I, we use JPG compression if, e.g., ||jpg(I)−I||/area(I) < 0.001 (1−ℓ), for some compression level, ℓ (or something along those lines).
You could get fancier and try using a reduced palette for the PNG, but that's a bit much and could be left to the implementer. Basically, once you define a measure of acceptable image artifacts as a function of compression level, you just have to come up with the best way to store the image. You could vectorize it for all I care. But most users wouldn't even care about that. Space and bandwidth is cheep. A default of ℓ=0.9 would produce either a standard PNG for any case that PNG is smaller and produce a 90%-quality JPG for photos. That would pretty much cover it.
There's lots you could do behind the scene to make a compression-level or image-quality slider meaningful, but first you need image support. Does this sort of format exist? Could it all be done in SVG (with embedded raster graphics)? (That would let you do this process on large image blocks which would help for heterogeneous content like screenshots.) Compression quality should be a job for a computer; users shouldn't have to worry about it.