You need this module if you work with images.

Once installed, you can size, crop, and change the format of images from anywhere... HTML, ASP.NET, ASP, PHP, Flex, or Flash ... Just add the desired behavior to the URL with "?width=100" or "?format=jpg". It supports scaling, cropping, rotating, flipping, stretching, padding, borders, transparency, jpeg, png, and gif formats. Aspect ratio is always maintained unless =fill is specified.

The difference between the actual size and wanted size of an uploaded image is inversely proportional to the quantiy of time available and the sluggishness of Photoshop.

Server-side image resizing is one of those little features that can have incredible ROI. It can save webmasters several hours each day, and gives you the ability to change the resolution of an image without having to hunt up the original.

I developed this image resizing system around two years ago. I needed something very intuitive, simple, secure, and efficient. We've been using this system heavily on a live, high-traffic site (youngfoundations.org) for two years, and we have had zero stability problems, memory leaks, or reliability issues with it. It's very mature and stable. Version 2.0 is even faster and more scalable than the previous versions, and includes dozens of new features.

Check out the samples page to see what it can do. The license is much like the GPL, and allows you to redistribute the source code as part of a larger project. You'll find the source code very clean, organized, and well commented.

If you have any questions after reading the documentation, leave a comment or e-mail support@imageresizing.net.

Although I typically release my components for free, I decided to charge a 'download fee' for this one to help support my other open-source projects. Don't worry, this component is still open-source, and the license permits source redistribution as part of a larger system. However, I'm asking that people who want to integrate this component purchase the download instead of ripping it out of another open-source project. My free to non-free LOC (lines of code) ratio is still over 40 to 1, and I plan on keeping it that way. I trust this will keep everybody happy.

Your donations are the reason Version 2 exists.

A few user comments...

To anyone thinking of using this module, it worked great and saved me lots of custom-coding time for a client project. On top of that, Nathanael reworked some of the code to my needs for a very reasonable rate, so I have the custom solution I needed.

If you're working on an image display project in asp.net, just use this code and enjoy. It's bullet proof!

Nathanael, I downloaded your code this weekend to use in our portal code base. I was tired of writing code to pick between icon/medium/large/original sizes of the images for different pickers / viewers etc. I was skeptical as to whether the component would be fast enough for the performance we are after in our software, but I am glad to report that your code is super fast and does exactly what you say it does. It was easy to install, and works perfectly. Thank you so much for building this tool, it is going to come in handy!

I do have one question though, which is why the tool will not resize an image to be larger than the original source image. I have a few images that are 800X600 jpegs, and when I tried ?width=1024 the code returned the original image size of 800X600? Is this by design? How hard would it be to make the code upsize and image? [v2 allows this with scale=both]

Again, thank you for the tool, and to other skeptic developers, Nathan's code rocks out of the box.

Thanks,
Steve

By Dave
just like to say, since using the code (and getting working and donating in next to no time) we have moved three or four of our sites over to using this technique. Previously we had manually run batch resizes initially and then made clients create multiple sizes of the image... very time consuming and some clients weren't technically up to the task. Having been after such a solution for so long, i was really worried that the time to generate images on the fly and the resultant quality would be a problem, but WOW..... this code nails it entirely...i can only say if you are reading these comments, worry not and get this code straight away.... so much work seems to have gone into this solution, i can't rate it too highly... my find of the year....... thanks Nathanael....

Querystring-based resizing is super-simple and can be used from any language (HTML, ASP.NET, PHP, Flash, Flex, etc).

For example, to make an image 400px or less wide, just add ?width=400. If you want to set both the maximum height and width, use ?maxwidth=400maxheight=400.

Sometimes you need all your images to be exactly the same size, regardless of the original aspect ratio. There are several solutions to this. If you specify both width and height, whitespace will be automatically added to two sides to make up the difference. Set whitespace color with bgcolor. If you don't want whitespace, you can try crop=auto. This "smart cropping" will figure out the minimal amount of cropping needed to center the image in the box without changing the aspect ratio or leaving whitespace. And, of course, you could stretch your images with stretch=fill... if you really wanted to.

Convert between jpg, png, gif, tiff, and bmp images with format=jpg|png|gif. Adjust the quality/size tradeoff of Jpegs with quality=1-100, and the palette size of GIFs and PNGs with colors=2-255

Not just for thumbnails - useful for resizing entire slideshows in real-time as the user changes the window size.

Bicubic resampling is used exclusively, resulting in very high-quality output. Jpeg compression is excellent, and uses the native windows JPEG encoder. Version 2.0 adds octree quantization for GIF and 8-bit PNG output, providing excellent palette generation for those also.

In my tests, the native windows JPEG encoder and Photoshop have the same visual quality and file size results. Expect photoshop-quality results for both JPEG and PNG output.

GIF and 8-bit PNG output is drastically improved in version 2.0 due to the addition of octree quantization. The primary difference you will notice between Photoshop and module output is the lack of dithering. In most scenarios this doesn't affect visual quality much and actually makes the image look 'cleaner'. Very gentle gradients do benefit from dithering, as do gradients against transparency.

File sizes are excellent - don't expect a measurable improvement when you use Photoshop or ImageReady to compress your images with the same quality settings.

The key to the excellent performance of this module is the disk caching system. This allows even a relatively low-end server to handle the same number of dynamic requests as static file requests.

Caching doesn't get in your way - if you modify the source file, the resized versions are also updated.

You can resize the same image to several different sizes, and the different versions are cached separately.

Managed disk cache. If the number of cached files exceeds the configured threshold, a cleanup pass is made on the directory, and a block of the least recently used files are removed.

Client-side caching directives are sent, minimizing repetitive requests from the same client.

Thumbnail generation in under 20 milliseconds for most images.

Suitable for slideshows and lists of images. Even the initial resizing of 50 images concurrently isn't noticeably slow.

Good with large source files (1-5MB)

Runs on any of the following following: Windows 2000, Server 2000, XP, Server 2003, Vista, Server 2008, or Windows 7*. *Not tested, but I don't know of any breaking changes to IIS occuring.

Requires .NET 2.0 or higher to be installed on the server and enabled on the website.

The customer must have the ability to copy and paste configuration settings, download files, copy files, and follow simple directions for configuring IIS 6 and below.

Users of version 1.0 should get the free upgrade to 1.2 if they wish to use IIS7 Integrated Mode.

While I do charge a download fee, the license allows you to redistribute the source as part of another open-source project. I'm trying to achieve several objectives: 1) Remove the need for users to track licenses, 2) Promote use in open-source projects, 3) Still provide financial support so the project can continue to evolve rapidly.

Complete source code and an example project is included

Clean, well documented, well designed code.

Great platform to build your own image processing systems on. You can use the disk caching system or image processing code independently from each other.

Very extensible, easy to add new features.

CustomFolders.cs can be *easily* modified to do all kinds of work:

Build rules to automatically resize images based on folder name or other criteria.

Add a new syntax for abbreviating or simplifying common resizing operations. Like /resize(w,h)/.

Easily perform URL rewriting for your images with String.Replace calls. (Regexes work too, if you like them).

By purchasing the download, you are permitted to

Modify and use the component in all of your projects.

Redistribute the source code as part of another project, provided the component
is less than 5% of the project (in lines of code), and you keep this information attached.

If you received the source code as part of another open source project,
you cannot extract it (by itself) for use in another project without purchasing a download
from http://nathanaeljones.com/. If nathanaeljones.com is no longer running, and a download
cannot be purchased, then you may extract the code.

This is basically a developer license - if you aren't a developer (i.e., a hosting company wanting a site or server license), please e-mail me (nathanael.jones@gmail.com).

About Nathanael

Nathanael Jones is a software engineer, father, consultant, and computer linguist with unreasonably high expectations of inanimate objects.
He refines .NET, ruby, and javascript libraries full-time at Imazen, but can often be found on stack overflow or participating in W3C community groups.

ImageResizer

I run Imazen, a tiny software company that specializes in web-based image processing and other difficult engineering problems.
I spend most of my time writing image-processing code in C#, web apps in Ruby, and documentation in Markdown.
Check out some of my current projects.