Saturday 16 February 2013

Code Tip #3 - Classic ASP Image Resizer (with options for cropping, padding, colouring and saving)

Like many other developers we're very comfortable using classic ASP and on the whole it does everything we need.

We know we should start moving across to VB.Net, but can't see many real benefits to compensate for the required learning curve.

The Problem


We'd like to be able to quickly and easily resize images and ASP doesn't offer any native commands, whereas VB.Net does.

After scouring the internet we came across a free ASP resizer from Pieter Cooreman, developer of a Classic ASP website content management system called QuickerSite.

His solution was simple. Use an aspx page to do the work and call it from a normal asp page.

Our Solution


We tried it and it worked perfectly, but there were a couple of things we wanted it to do that Pieter's code didn't, so we adapted it to include more querystring options, annotation and instructions.

The resulting image resizer will do the following:

  • Accept and convert jpeg, png, gif and bitmap files.
  • Convert images at a relative size to a given width or height.
  • Resize to a fixed width, either cropping or padding (with colour) the resulting image if the dimensions differ.
  • Add special effects including greyscale and sepia.
  • Output the resulting jpg to either the screen, a file or both.

All you need to do is call it from your ASP page with the relevant querystring values.

Instructions / Download


Download the zip file here: ClassicASPImageResizer.zip

Unzip the file to a folder on your server / local machine and run the default.asp for instructions and to see the code in action.

Credits


This solution was originally developed by Pieter Cooreman, QuickerSite (Classic ASP Website CMS). It was adapted and republished by David Barton, EasierThan Website Design.

The script is offered freely and no liability is accepted by either party for any issues arising from the downloading, installing or use of it.

If you find the script useful, backlinks and / or a beer (see original ASP Image Resizer page) would be much appreciated, but are not necessary.