I'm sitting in on Prayank Swaroop's Image Manipulation in ColdFusion session right now. It's the last of three sessions on new features/functionality coming out in ColdFusion 8 (Scorpio). Image manipulation is something a LOT of people have been asking for for quite a long time, so it's nice to see it finally being implemented.

The new cfimage tag and over 45 supporting functions will support the following:

  • Creating images
  • Image conversion
  • Thumbnails and resizing
  • JPEG compression
  • Adding text
  • Watermarking
  • Base64 support
  • Captchas
  • Blobs
  • Exif and IPTC (only for JPEG)
  • Basic graphic functions
  • Magic of drawing strokes

view plain print about
1<cfimage source="foo.jog" name="myImage" action="read">
2
3<cfset myImage = imageNew("foo.jpg")>

Inputs include URL's, files,

You'll be able to read in all sorts of meta information about images - dimensions, color space, resolution, etc.

Image conversion supports jpg, gif (not animated), png, bmp and tiff. Other formats that can be read/written but have not been tested are FlashPix, etc.

If you're working with jpegs, you can specify the compression rate (0.75 is the default) using the quality attribute of the cfimage tag.

Image manipulation includes Rotate:

view plain print about
1<cfset foo = imageRotate(myImage, 45)>

Resize:

view plain print about
1<!--- 2nd attribute is width, 3rd attribute is height --->
2<cfset foo = imageResize(myImage, "50%", "")>

Border:

view plain print about
1<!--- 2nd atribute is thickness, 3rd is color,4th is border shape --->
2<cfset foo = imageAddBorder(myImage, 5, "red", "constant">

Many more functions including imageShear, imageNegative, imageBrighten, imageBlur, etc.

Image resizing can be fixed width and height, proportional, and scale to fit.

Because there are so many functions, with lots of repeating attributes, you can use attribute collections and pass them to the image functions.

Base64 support allows you to embed images in HTML pages and emails. The new tags/functions allow you to do this a little easier than the current cffile/toBase64() method.

The cfimage tag will also support PNG captchas:

view plain print about
1<cfimage action="captcha"
2width="600"
3height="150"
4text="SAMPLE"
5difficulty="low" <!--- low, medium, high" --->
6destination="captcha.png">

Another cool feature is blob support. You'll be able to read and write blobs as well as convert images to blobs, making inserting and retrieving images from a database easy.

Exif and IPTC image metadata standards are supported for JPEG images. You can use the imageGetExifMetaData() and imageGetIPTCMetaData() functions respectively. There currently aren't any write functions, but that is subject to change before release.

There are quite a few drawing functions as well: geometric primitives, cubic and quadratic curves, and more. I think these are going to be interesting. One use case I have is diagraming workflow's. We have a workflow engine we use in several of our applications. It would be pretty cool to use the image drawing functions to actually diagram the workflow within a workflow administration application to make visualizing the workflow easier.

It looks to me like the cfimage tag and related functions in Scorpio are finally going to deliver a pretty powerful feature set that's been sorely lacking in ColdFusion for some time. Kudos to the development team on the implementation so far.

Given the information from the presentation, is there anything you feel the team may be missing?