Using Coldfusion's ImageNew() with imageOverlay()

UPDATE: read here

I am working on a web app where users are allowed to upload images. All the images need to be square when displayed so I planned to use the imageOverlay() function in Coldfusion to create a blank square image and then overlay the uploaded image on top of it. I was using the imageNew() function to create the square image dynamically based on the height and width of the uploaded image. It seemed like it would work, but every time I uploaded an image imageOverlay() would crap out with the error “Overlay operation requires the two sources to match in number of bands and data type.”

I did a Google search for this error and there was only one relevant result with this error from Ray Camden’s blog. He couldn’t figure out how to fix this error either and created a work around by duplicating and then transforming his original image to his needs.

I really wanted to use ImageNew(). The functionality was there, but it just wouldn’t work. This felt just like another Coldfusion ‘gotcha’ (isDefined(“session.myVar”)!) but figured I could come up with a work-around. My solution was to save the file to a temp directory and then load it again. Once this is done the image will work with imageOverlay.

There’s got to be a better way to make this work. Anyone?

Below is my workaround:

Leave a Reply

Your email address will not be published. Required fields are marked *