Quantcast
Viewing latest article 11
Browse Latest Browse All 15

Generate thumbnails on the fly - Yet another version

There are many posts how to generate thumbnails using ASP.NET. Some good some less. Be sure to get distance from the versions that use Image.GetThumbnailImage method.

I'm using my own version that going with me from project to project and it is an HttpHandler that registered in the web.config. You can specified maximum height, maximum width, both, specified quality (1-100) and if the image will be cached or not. It is working well with .jpg, .bmp, .png and .gif. The code is too long to write it here, but it is really easy to undestand and really easy to implement and use it.

To use it, add the class to your dll or just drop it in the App_Code folder,register the handler in the web.config as the following:

<add verb="*" path="image.axd" type="Miron.Web.ImageHandler" validate="false"/>

In your site, to generate a thumbnail with size 150X150 in 90% quality (The image will be cached automatically):

<img src="image.axd?src=~/images/photo.jpg&amp;w=150&amp;h=150&amp;q=90">

If you want the image to not be stored in the cache:

<img src="image.axd?src=~/images/photo.jpg&amp;w=150&amp;h=150&amp;q=90&amp;nocache">

 

You can see it in action in the gallery I did to my new nephew Noam: http://mironabramson.com/noam

Hope it will be useful.

ImageHandler.zip (2.85 kb)


Viewing latest article 11
Browse Latest Browse All 15

Trending Articles