About the author

Miron Abramson
Me
Software Engineer,
CTO at PixeliT
and .NET addicted for long time.
Open source projects:
MbCompression - Compression library

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2014

Creative Commons License

Blog Flux Directory
Technology Blogs - Blog Top Sites

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)

Currently rated 4.2 by 6 people

  • Currently 4.166667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: ASP.NET | C#
Posted by Miron on Sunday, February 08, 2009 7:51 AM
Permalink | Comments (6) | Post RSSRSS comment feed

Related posts

Comments

DotNetKicks.com

Sunday, February 08, 2009 9:05 AM

trackback

Trackback from DotNetKicks.com

Generate thumbnails on the fly - Yet another version

Watch UFC 95 Live Stream us

Sunday, February 08, 2009 6:30 PM

Watch UFC 95 Live Stream

I found your site very interesting. Thanks

ufc 95 live us

Wednesday, February 11, 2009 2:21 PM

ufc 95 live

Thank you for this tips. Will try this on my other site. keep it up.

Petr Snobelt cz

Wednesday, February 18, 2009 7:11 PM

Petr Snobelt

Why reinvent wheel, try ImageGen
www.percipientstudios.com/imagegen/overview.aspx

Miron il

Wednesday, February 18, 2009 9:17 PM

Miron

@Petr,
ImageGen is not open-source and not free...
Mine is.

Rose

Friday, October 30, 2009 8:58 AM

Rose

Hello Miron,
I saw your comment on this site: pietschsoft.com/.../...bmail-Screenshot-Image.aspx, and I noticed you had the same issue as I do with the white square. Have you by any change solved the problem? Do you have any other solution for it using C#? Thanks!