I recently set out to redesign my image gallery in Coldfusion. Currently it's in PHP. There is nothing wrong with the php version, but I want to start doing some database stuff, and I have to admit I "get" the Coldfusion database interaction stuff better. It seems easier and more natural to me. Anyway, enough about my shortcomings....
One of the first things I wanted to get right was the image resizing. I'm real lazy and just want to throw all the images in a folder and left the front end sort it out. In PHP I use a heavily modified version of PHPIX2 (Google it; you'll find it) in which I use ImageMagik's convert command to do the resize from a system call. Yuck and insecure, I know... I didn't want to do this with CF so I set out to try every image "tag" I could find. I won't name the 6 I tried, but they all fell short in one way or another. Quality and speed were the problems most seen.
I wanted to use good old ImageMagick, so after some poking around I landed on the Jmagick page. Earlier in the day I had implemented Drew Noakes's metadata extractor for EXIF information and I was very impressed with the ease of using Java with Coldfusion and figured I'd give Jmagick a go.... Easy right? Well, no it wasn't..... The reward at the end was though.
Here is the quick and dirty version, I hope it helps somebody as information on doing this is non-existent. And before you say: 'Use CFX_OpenImage as it's based on ImageMagick...". It is, and it works very well, but it's based on Version 5 of IM and the quality suffers some. It's slower for the same operations also. If you want the easy way out I do highly suggest you use CFX_OpenImage over anything else.
I use Coldfusion 7.01 Standard on windows. You must upgrade to the 1.5 JVM from Sun. In order to do that you must upgrade JRun to 4 updater 6. There is info out there on how to get that done. It's not supported by Adobe though so you are on your own. It works fine for me.
Download the Jmagick.jar and dll from the webpage, I used the 6.2.6-8-Q8 pre complied version. While your there grab the Q8 version of ImageMagick. Install ImageMagick as normal and put the Jmagick files in your CF java class path folder AND in the jre "/etc" folder. It had to be in both places to work. That was a bugger to figure out.
Once it worked using Jmagick was the fastest and highest quality method to do resizing in CF. Others were a bit faster, but the results were not as nice.
Below is some sample code.
<!--- Tell jmagic to use the system classloader --->
<cfset System = CreateObject("java", "java.lang.System")>
<cfset properties = System.setProperty("jmagick.systemclassloader","false") />
<!--- Create ImageInfo and read the jpg --->
<cfobject name="info" type="java" action="create" class="magick.ImageInfo" />
<cfset info.init("C:\test.jpg") />
<!--- Create MagickImage --->
<cfobject name="image" type="java" action="create" class="magick.MagickImage" />
<cfset image.init(info) />
<!--- Resize the image --->
<cfset image = image.scaleImage(725,482) />
<!--- Set jpg quality to 88 --->
<cfset info.setQuality(88) />
<!--- Sharpen the image --->
<cfset image = image.unsharpMaskImage(0,1,1.2,.02) />
<!--- Remove all profiles. EXIF, IPTC, etc.. --->
<cfset image.profileImage("*", (JavaCast("null", ""))) />
<!--- Name the new file and write it out --->
<cfset image.setFileName("c:\smaller.jpg") />
<cfset image.writeImage(info) />