Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at the New York ColdFusion User Group (May. 2008) with:

ColdFusion 8.0.1 Bug Coldfusion.Image.ImageWriter $ ImageWritingException

By Ben Nadel on
Tags: ColdFusion

I just came across a known bug in ColdFusion 8.0.1. Apparently, sometimes the ColdFusion image functions don't play nicely with JPG image files and throw the following error:

An exception occurred while trying to write the image. Ensure that the destination directory exists and that Coldfusion has permission to write to the given path or file. cause : coldfusion.image.ImageWriter$ImageWritingException: An exception occurred while trying to write the image.

Some quick googling found that there was a Hot Fix available for ColdFusion 8.0.1 image functions. I figured I would post it here in case anyone was running into the same problem.

ColdFusion 8.0.1 CFImage / Image Functions Hot Fix

ColdFusion 8.0 And Later Hot Fixes

I installed the above ColdFusion 8.0.1 Image hot fix, restarted my ColdFusion service, and the image that was breaking my application started working again.



Reader Comments

Hey Ben, I've been working with the jpg issues for a while. I've noticed that some jpg's don't play nice even after the hotfixes are applied.

It may be a hack, but I got fed up and had to do something....I'm converting the jpg's to gif's (usng CFIMAGE action="convert") after they're uploaded and then doing the CFIMAGE manipulation (resizing etc) on them. Its an extra step, but it's working like a charm for my site.

I hope this helps!

Reply to this Comment

@Dan,

Interesting hack. Unfortunately, converting a large JPG to a GIF will increase the file size greatly (in theory)? But, good to have at least on solution till they iron out the kinks.

Reply to this Comment

Thanks for the Tip, this problem was driving me crazy, 1 jpg works fine, then next one does not!

Your site rocks!

Reply to this Comment

I had the same problem, and the hot-fixes didn't seem to help. Not quite sure where the client was getting their jpgs from :)

As a fix, I found that saving the image to disk and then reloading it worked. The extra step seemed to convert the jpg to a format that didn't have the problems.

It's not perfect, as it slows things down and probably reduces image quality. It required the least effort though, and doesn't have the issues associated with converting the image format to gif.

Reply to this Comment

@Gareth, can you explain further how you got this to work. the hotfix is not working for me either and converting to .gif's is too much load and file size. what do you mean by saving the image to disk and then reloading it. can you provide sample code?

Reply to this Comment

It's while ago, but I think I just used cfimage to save the file without modification.
I then reload the new image and do whatever manipulation that's needed.
It doesn't fix all images, but reduced a lot of the problems

Reply to this Comment

I'd still be starting at a page of code if it wasn't for this post: I had an issue with three file uploads in one form that stopped working after we upgraded to 8, thanks!

Reply to this Comment

I commented earlier about converting .jpg's to .gif as a workaround. I've since learned that my .jpg problems stemmed from trying to constrain both the height and width of the .jpg using CFIMAGE action="resize". Sometimes my users would upload a .jpg (book covers in this case) and the dimensions were such that constraining it too far "out of whack" from the original size would cause the page to break. I've since removed the "width" attribute of the CFIMAGE tag, but I still explicitly set the "height"...the width is constrained automagically (thanks CF)...it works perfectly except for the occasional user that uploads something really funky...like a banner image rather than a book cover...lol :-)

Reply to this Comment

I found that using the cfimage info to determine what's been uploaded seemed to be best, so I have something like this

<cffile action="UPLOAD" filefield="upload2" destination="#application.path#www\alt_images\" nameconflict="MAKEUNIQUE">
<cfimage action="info" source="#application.path#www\alt_images\#cffile.ServerFile#" structname="info">
<cfif info.width gte info.height>
<cfimage action="resize" source="#application.path#www\alt_images\#cffile.ServerFile#"
destination="#application.path#www\alt_images\thumbs\#cffile.ServerFile#" height="" width="100" overwrite="yes">
<cfelse>
<cfimage action="resize" source="#application.path#www\alt_images\#cffile.ServerFile#"
destination="#application.path#www\alt_images\thumbs\#cffile.ServerFile#" height="100" width="" overwrite="yes">
</cfif>

Reply to this Comment

Another interesting twist on this issue for the benefit of anyone else who might have trouble. We were using CF8 to write images across the network and had to alter the run-as user for the CF instance in order for the image writing to work.

However, when re-starting the instance via JRun Admin, those permissions were not set - resulting in the aforementioned exception. Re-starting the Windows service that CF was running under fixed the issue.

Reply to this Comment

@Scott,

Thanks for the links. I need to check to see where my server is on these updates.

@Jeff,

Very interesting situation you got going on there.

Reply to this Comment

Another workaround for those "stubborn" jpgs: use <cffile action="readbinary" ...> and feed the variable (name) to <cfimage action="resize" ...>

This worked for me =)

Reply to this Comment

I have this issue with CF9!

I just give the file url to this custom function I wrote:

<cffunction name="ImageClean">
<cfargument name="dirty">
<cfimage action="convert" source="#dirty#" destination="#dirty#.png">
<cffile action="delete" file="#dirty#">
<cfimage action="convert" source="#dirty#.png" destination="#dirty#">
</cffunction>

Reply to this Comment

@Laurent,

That's lame that this is still a problem in CF9 = but, I'm glad the convert approach still works.

Reply to this Comment

@Ben,

I agree,

Also, another thing is the speed. I just had to convert my image module to stop using CFX_IMAGE (could not find the 1.6.6.15 update who solves the IE7+ color issue) and it is just so slow now, like 30 secs instead of 5 for generating 5 different resizes.

Reply to this Comment

I'm interested in doing whatever I can to get the performance of CFIMAGE up to acceptable standards. In my AIR app, the user uploads a full size image (500 x 500) and then CF auto-generates medium and thumbnail images. But it is slow. I'm almost considering manipulating the image in the AIR app before uploading! Any advice on how we might address the performance issues in the meantime?

Reply to this Comment

@Jeff,

Have you tried adjusting the quality of the image that you are making? I think ColdFusion defaults to highest quality / slowest speed.

Reply to this Comment

Good idea! Thanks. I'll have to play around with that - these images are used for an online catalog but the medium/thumbnail images don't have to be of high quality.

Reply to this Comment

Well I've lost an entire day on this issue...my CF8/Win would simply not write a JPEG....everything else worked... my workaround to avoid using ImageWrite is:

<cffile action="write" file="#ExpandPath('/my_path/my_image.jpg')#" output="#ToBinary(ToBase64(my_jpg_variable))#">

Reply to this Comment

@Antoine,

My CF8 image stuff has recently started messing up with writing images (not sure what I did to mess it up - looks like I might need one of the updaters or something). To get around this for the moment, I have started using the same work-around - using the file-write of the underlying binary data.

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.