views:

29

answers:

3

Hi,

I am working on a web application where images has to be scaled dynamically and served to the client as fast as possible (with low overhead). I need to create something that scales and compresses high-quality PNGs to medium quality JPEGs.

Now, there are multiple ways of doing this and I am slightly confused which method provides the best solution for the application to be as fast as possible - and I was hoping you guys could guide me in the right direction.

This application will run on the .NET 3.5-platform and I am looking for fresh ways of doing this. Googling has given me some clues but most of the articles I found were VERY old (2000-2005 or so).

The client app is written in ASP.NET MVC, while the backend app is written in Web Forms. The images are located in a directory in the Web Forms application, but I guess that dosen't say the image handler must be written in Web forms.

So, do you have any suggestions?

  • Suitable technique to use (HTTP Handlers, MVC, Static files with FTP or something else?)
  • Any good articles on the subject (spare me the old ones)
  • How to cache the images?
+1  A: 

Have you thought about a dedicated image server? e.g. Scene 7 or something similar?

You could build one yourself, but unless this is part of your core application functionality, it would probably be better to use something pre-built (whether paid or free).

Eric Petroelje
Interesting suggestion. This is a low budget project and hosting one IIS server is all we can do at the moment, but I will keep this tip in mind for future projects!
Mickel
@Mickel - there may be some free/open source image server projects out there. A quick google search didn't turn up anything for me, but others may be able to point something out.
Eric Petroelje
A: 

1) I would personally use ASP.NET MVC itself instead of re-inventingthe wheel. Implementing any custom handler can only be slightly faster which I do not believe is worth it. I have not seen an ImageResult yet but it is easy to create one that can handle various file types.

2) Scaling images is a fairly easy task. I would personally use OpenCV to do that since it is very fast and flexible. It also has a managed wrapper (Emgu) but I have not used it.

3) Just use ASP.NET caching and I will use the image path and its scale to set the URL to the image. e.g. http://server/image1/0.5

Aliostad
A: 

IMO, it really does not matter what you use - handler(ashx), page(aspx) or MVC to resize and serve the image. Use routes if you want user-friendly URLs. But most important thing would be to use caching - you can set response cache headers and/or use ASP.NET output caching and/or cache your thumbnail images on local file system (IMO, you should cache at all levels for best performance).

See here one sample code for generating thumbnails: http://www.west-wind.com/weblog/posts/283.aspx (this one is actually pretty old but it illustrates use of output caching).

Refer this article for comparison (speed vs quality) of resizing images using GDI/WPF/WIC: http://weblogs.asp.net/bleroy/archive/2009/12/10/resizing-images-from-the-server-using-wpf-wic-instead-of-gdi.aspx

VinayC