I ran into an interesting problem with ColdFusion 8's image functions. I wanted to compare my image from before I added my effect, and my image after. Simple right? Well no, no its not. I'm doing my image manipulations in function, so I wanted to pass in the original image, and save the result to a new variable, but I kept coming out with two copies of the same image. It took me a bit, but I finally found a solution.
It turns out that not only does CF8 pass its images by reference, it seems to duplicate those references every where.
<cfset var myImage = Duplicate(arguments.image)/>
<cfset var myImage = CreateObject("java", "coldfusion.image.Image").init(arguments.image)/>
<cfset var myImage = ImageNew(arguments.image)/>
What do those statements have in common? They all return a reference to the original image rather then an independent copy of the image. In the end, the only way to get that copy is with the following code.
<cfset var info = ImageInfo(arguments.image)>
<cfset var myImage = ImageNew("", info.width, info.height, "argb", "red")/>
<cfset ImagePaste(myImage, arguments.image, 0, 0)/>
Thats really annoying.