views:

45

answers:

3

Goal:

I have lots of pictures in many sizes (both dimensions and file size)

I'd like to convert these files twice:

  1. thumbnail-size pictures
  2. pictures that will look OK on a web page and will be as close to a full screen as possible... and keeping the file size under 500KB.

HTML Questions:

A. What is the best file format to use (jpg, png or other) ?
B. What is the best configuration for web ... as small as possible file size with reasonable quality

C# Questions

A Is there a qulity way to achieve this conversion with C# code (if yes how)?

A: 

I think PNG is better format for WEB than JPEG that always uses lossy JPG compression, but its degree is selectable, for higher quality and larger files, or lower quality and smaller files. PNG uses ZIP compression which is lossless, and slightly more effective than LZW (slightly smaller files).

In C# you can use System.Drawing namespace types to load, resize and convert mages. This namespace wraps GDI+ API.

Vokinneberg
A: 

A. For graphics I would use png and for fotos jpg.

B. Configuration?

C. There are tons of post that explain that:
http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx
http://stackoverflow.com/questions/87753/resizing-an-image-without-losing-any-quality

Remy
+1  A: 

Try the code in this small C# app for resizing and compressing the graphics. I have reused this code for use in an ASP.NET site without too much work, hopefully you can make use of it. You can run the app to check quality fits your needs etc.

http://blog.bombdefused.com/2010/08/bulk-image-optimizer-in-c-full-source.html

You can pass the image twice, specifying dimensions for a thumbnail, and then again for your display image. It can handle multiple formats (jpg, png, bmp, tiff, gif), and reduce file size significantly without loosing noticeable quality.

On .jpg vs .png, generally jpg is better as you will get a smaller file size than with png. I've generally used this code passing a quality of 90%, which reduces file size significantly, but still looks perfect.

BombDefused
BombDefused, I have to accept your answer cause it gives me exactly what I need :)So now I can create relatively big pictures for the web with small files size. Yet I really don't understand jpg vs. png nor what causes a file to get so big... hope that after learning the code you gave me I'll be smarter... thank you very much. Asaf
Asaf
You don't really need a great understanding of the workings of varying file formats. The formats you're working with here are all classes of 'bitmap'. .NET has codecs for dealing with these but as far as your concerned, you can deal with them in the same way.PNG's are lossless formats and use special algorithms to find patterns in the image that can be expressed in with less data. This works best with simple images such as logos with a relatively low number of colours. If you are working with photos or many gradients in an image, jpg files will usually result in smaller files.Good luck!
BombDefused