Image Paste Bug In Lucee CFML
Last week, in my post on rendering QR Code images with Zxing in ColdFusion, I had mentioned at the end of the post that I ran into issues in Lucee CFML with using a BufferedImage
as the source to a ColdFusion image object. Yesterday, Zac Spitzer asked me to come up with an isolated reproduction of the issue. And, in doing so, I realized that my assessment was slightly off - it's not a BufferedImage
issue, it's an imagePaste()
issue. It seems that in Lucee CFML, once you paste one image into another, no subsequent drawing operations work (on that destination image).
Here's a production of the problem - it runs two tests: one without and then one with an imagePaste()
operation. Each test attempts image drawing operations both before and after the paste operation.
<cfscript>
// The only difference in the two tests is that one will perform imagePaste().
tests = [ false, true ];
results = tests.map(
( doPaste ) => {
var black = imageNew( "", 20, 20, "rgb", "000000" );
var white = imageNew( "", 100, 100, "rgb", "ffffff" );
// Draw MAGENTA boxes BEFORE paste.
white.setDrawingColor( "ff3366" );
white.drawRect( 10, 10, 20, 20, true );
white.drawRect( 30, 30, 20, 20, true );
white.drawRect( 50, 50, 20, 20, true );
white.drawRect( 70, 70, 20, 20, true );
// Pasting one image into another seems to corrupt the destination image
// (in Lucee CFML); and, prevents subsequent image manipulation operations.
if ( doPaste ) {
white.paste( black, 70, 10 );
}
// Draw CYAN boxes AFTER paste.
white.setDrawingColor( "008b8b" );
white.drawRect( 10, 40, 10, 10, true );
white.drawRect( 30, 60, 10, 10, true );
white.drawRect( 50, 80, 10, 10, true );
return white;
}
);
</cfscript>
<cfoutput>
<cfloop array="#results#" item="image" index="i">
<div>
<!--- Write the image to disk. --->
<cfimage
source="#image#"
action="write"
destination="#expandPath( './#i#.png' )#"
overwrite="true"
/>
<!--- Render image we JUST wrote to disk. --->
<img src="./#i#.png" />
<cfdump var="#imageInfo( image )#" />
</div>
</cfloop>
</cfoutput>
If we run this ColdFusion code in Lucee CFML, we get the following output:
As you can see (in Lucee CFML), the cyan boxes are only drawn in the test in which the imagePaste()
operation is not performed. Once we paste one image into another, the subsequent drawing operations appear to have no effect.
As a control, if we run the same ColdFusion code in Adobe ColdFusion 2025, we get the following output:
As you can see (in Adobe ColdFusion 2025), the cyan boxes are drawn regardless of whether or not the imagePaste()
operation is performed.
Want to use code from this post? Check out the license.
Reader Comments
Thanks for the repo Ben, seems to be possibly a Lucee 6 regression
On trycf, Lucee 5.4 has the image extension 2.0.0.26 vs Lucee 6.2.1 having 2.0.0.29
Workaround, doing a duplicate after the paste seems to work
https://luceeserver.atlassian.net/browse/LDEV-5640
@Zac,
Good catch on the
duplicate()
- that will be good to know going forward.Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →