Question

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)?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top