0

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 good way to achieve this conversion using C# code (if yes, how)?

dplante
  • 2,387
  • 3
  • 20
  • 26
Asaf
  • 2,857
  • 9
  • 31
  • 52

3 Answers3

1

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.

gb2d
  • 6,160
  • 8
  • 51
  • 97
  • 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 Aug 20 '10 at 08:38
  • 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! – gb2d Aug 20 '10 at 15:57
0

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
  • 1,852
  • 2
  • 18
  • 31
0

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
Resizing an Image without losing any quality

Community
  • 1
  • 1
Remy
  • 11,899
  • 13
  • 60
  • 97