Open-source image resizing module for ASP.NET. Great for thumbnails and slideshows. Features managed disk caching, jpeg/png/gif support, and bicubic resizing.
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 &stretch=fill is specified.
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.
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.
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.
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...
Querystring-based resizing is super-simple and can be used from any language (HTML, ASP.NET, PHP, Flash, Flex, etc).
Supports scaling, cropping, rotating, flipping, stretching, padding, borders, transparency, and the 4 main image formats. Aspect ratio is maintained unless &stretch=fill is specified.
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=400&maxheight=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.
You can select any frame of an animated GIF with ?frame=x, and any page from a TIFF file with ?page=x.
Manually crop out parts of an image with ?crop=(x1,y1,x2,y2). Rotate with ?rotate=degrees. Flip with ?flip=h|v|both.
And the best part - add borders and paddings without causing CSS layout bugs!
Check out the samples page to see all the features in action.
- Supported input formats: BMP, GIF, JPG, PNG and TIFF
- Supported output formats: JPG, PNG, and GIF
Command Reference
- width, height - force the width and/or height to certain dimensions. Whitespace will be added if the aspect ratio is different.
- maxwidth, maxheight - fit the image within the specified bounds. (Most often used)
- crop=auto - Crop the image the the size specified by width and height. Centers and minimally crops to preserve aspect ratio.
- crop=(x1,y1,x2,y2) - Crop the image to the specified rectangle on the source image. You can use negative coordinates to specifiy bottom-right relative locations.
- rotate=degress - Rotate the image.
- bgcolor=color name| hex code (6-char). Sets the background/whitespace color.
- stretch=fill - Stretches the image to width and height if both are specified. This is the only way to lose aspect ratio.
- scale=both|upscaleonly|downscaleonly - By default, images are never upscaled. Use &scale=both to grow an image.
- flip=h|v|both - Flips the image after resizing.
- sourceFlip=h|v|both - Flips the source image before resizing/rotation.
- paddingWidth=px & paddingColor=color|hex. paddingColor defaults to bgcolor, which defaults to white.
- borderWidth=px, borderColor=color|hex.
- format=jpg|png|gif
- colors=2-255 - Control the palette size of PNG and GIF images. If omitted, PNGs will be 24-bit.
- frame=x - Choose which frame of an animated GIF to display.
- page=x - Choose which page of a multi-page TIFF document to display.
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.
- Runs on any of the following following: Windows 2000, Server 2000, XP, Server 2003, Vista, or Server 2008.
- Requires .NET 2.0 or higher to be installed on the server and enabled on the website.
- 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).
Releases
- 1.0 - August 6, 2008 (Initial release to the public.)
- 1.2 - Nov 23, 2008 (Upgrade Notes from 1.0 to 1.2) (Original product page)
- 2.0a Jan 30, 2009 (E-mail distribution)
- 2.0a Mar 4, 2009 (E-mail distribution)
- Fixed: Cleanup routine can cause bottleneck on GetFiles() - fix so that Directory.GetFiles() only happens at startup and when items are added. Only affects sites with slow filesystems (or without filesystem caching), and with thousands of images.
- Fixed: imagecache/ is not protected when AllowURLRewriting is enabled
http://localhost/resize(40,40)/imagecache/1639776677.jpg
bypasses it. Added protection in the HttpModule.
- Fixed: Potential issue in Quantizer.cs that may cause lines in GIF output.
- Fixed Maxwidth/maxheight not getting picked up.
- Fixed: Custom crop coordinates at 0 were being applied in the negative coordinate zone. Fixed so x1,y1 weren't affected, but setting x2 and y2 to 0 is bottom-right relative.
- Changed flip to be after all operations, and added sourceFlip to replace its behavior.
- Added -ignoreicc parameter and made ICC reading the default. ICC profiles are not written out - browser do not support them.
- 2.0b May 16, 2009 (Upgrade notes from 1.2 to 2.0)
- Fixed: Incorrect aspect ratio issue if both maxwidth, width, and height are specified.
- Fixed: UNC hosted websites are now supported.
- Added DisableCacheCleanup command, and made MaxCachedImages < 0 behave the same as DisableCacheCleanup=true
- Fixed: rounding error that could cause a pixel line on the right and/or bottom sides of the image. Rare floating point rounding error in GDI native code. Added code to force rounding to be consistent.
- 2.0rc1 May 21, 2009 (Upgrade notes from 1.2 to 2.0)
- Fixed: Transparency is preserved more reliably with GIF files. Certain GIF files were losing transparency because the way the color palette was constructed.
- Fixed: .tif is now a supported input extension... previously only .tiff and .tff were allowed.
- Added WatermarkSettings.cs class for watermarking. Easy to extend for your own use.
- Converted ImageManager from a Static class to a normal class with a getBestInstance() static method. Allows easy plugin creation for ImageManager.
- Added support for ?frame=1-x and ?page=1-x. You can now select frames from GIF images and pages from TIFF files. Removed ?time
- Hashes are now SHA-256 instead of .NET 32-bit. They are base-16 encoded. This results in longer file names, but astronomically low chances of hash collisions.
- Fixed upgrade notes link in upgrade notes.txt
2.0rc2 Jun 3, 2009 (Upgrade notes from 1.2 to 2.0)
- Fixed: Extremely rare bug where rounding causes Bitmap to be initialized with a dimension of 0, and causes a Parameter exception.
Ocurred when resizing an image to < 2px in height or width (usually happens with 2x1000 size images, etc).
Added regression test for 500x2 image resized to 100px wide.
-
Fixed: Typo (missing else) in SaveToNonSeekableStream. This method is for extensibility, and is not used by the Resizer directly.
This method is now tested and part of the Regression tests (HandlerTest.ashx).