In Lucee 5.x the behaviour of casting image objects to strings has changed.
In Lucee 4.5 I'm not certain exactly how the function worked but the following worked as expected to read an image and write it back to disk:
image = ImageRead('test.jpg');
binary_image = toBinary(toBase64(image));
file action="write" output="#binary_image#" file="output.jpg";
Howevever in Lucee 5 this results in a corrupt image. I checked the output image file contents and discovered the image had been written as:
In other words it was converted to a HTML data: image embed. I tested the intermediate functions and found that toBase64() created the above HTML string as Base64. The same behaviour was also observed with toString(image) so obviously this is a string cast issue.
I don't believe this is the behaviour people would expect from toString() on an image object since there really should not be any expectation that the string be converted to a HTML tag. I can see why that may seem convenient in some cases like cfdump but it creates undocumented, unexpected results.