As a follow up to my previous post. The best way to avoid this issue is to just use the imagePaste function. It can do the same thing as imageOverlay, and it won’t complain when you use imageNew()
Month: December 2009
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:
Coldfusion SESSION and COOKIE scope
Working with both SESSION and COOKIE scope tripped me up today so I wanted to illustrate what went wrong so hopefully others can avoid this.
This sets a session variable that will exist for the life of the session.
This sets a cookie that will exist for the life of the browser session.
This sets a cookie that will expire in 8 hours.
In my application.cfc I had set:
I had incorrectly thought that this timespan would also apply to the COOKIE scope, but it does not.