Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically choosing image conversion format to JPEG or PNG for Silverlight display

Tags:

.net

image

png

jpeg

I have a project where I need to convert a large number of image types to be displayable in a Silverlight app - TIFF, GIF, WMF, EMF, BMP, DIB, etc. I can do these conversions on the server before hydrating the Silverlight app.

However, I'm not sure when I should choose to convert to which format, either JPG or PNG. Is there some kind of standard out there like TIFF should always be a JPEG and GIF should always be a PNG. Or, if a BMP is 24 bit, it should be converted to a JPEG - any lower and it can be a PNG. Or everything is a PNG and why?

What I usually see or see in response to this type of question is "Well, if the picture is a photograph, go with JPEG" or "If it has straight lines, PNG is better." Unfortunately, I won't have the luxury of viewing any of the image files at all and would like just a standard way to do this via code, even if that is a zillion if/then statements.

Are there any standards or best practices around this subject?

like image 719
Todd Main Avatar asked May 13 '10 01:05

Todd Main


3 Answers

The simplest thing that could possibly work is "keep all the detail" ("100% quality"), i.e., always use PNG rather than JPEG.

PNG images always look identical to the original (it is lossless). JPG images usually look about the same as the original, but on some images (such as line art) JPG gives weird compression artifacts (it is lossy).

  • It doesn't help to convert JPEG images to PNG images. So pass JPEG files straight through without conversion. If a TIFF container file contains a JPEG image, then extract it to a standard JPEG format file; otherwise it's probably best to convert that TIFF file to PNG.
  • consider making both a JPEG file and a PNG files; if the JPEG file is "significantly" smaller than the PNG file, use the JPEG file.
  • ".emf" and ".wmf" are inherently vector-based, rather than raster graphics. PNG is better than JPEG for vector graphics, but best would be a vector file format. Is it possible to use the standard vector graphics format (".svg")?
like image 124
David Cary Avatar answered Nov 11 '22 03:11

David Cary


One big advantage of JPG over PNG is that JPGs provide a good balance between picture size and quality. If file size isn't a concern then PNG is probably the way to go as it offers more flexibility than JPG. This doesn't really answer your question, though.

like image 33
NakedBrunch Avatar answered Nov 11 '22 01:11

NakedBrunch


You can use a service like Smush.it - it will tell you the best optimized format for the images, and run the compressions for you.

If I recall correctly, they run all compressions on each image, then compare the outcomes... returning the best of the set.

like image 36
scunliffe Avatar answered Nov 11 '22 03:11

scunliffe