ColdFusion 8 ImageResize() / ImageWrite() Bug?

Posted August 16, 2007 at 2:21 PM

Tags: ColdFusion

Boris just pointed out a peculiar problem to me. I have been playing around with it, and it appears to be a bug. When you use ColdFusion 8 to resize a COMPLETELY transparent GIF image and then try to write it back to the file system, ColdFusion throws 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 : java.lang.NullPointerException

Here is the code that produces this error:

 Launch code in new window » Download code as text file »

  • <!--- Read in 100x100 transparent GIF image. --->
  • <cfimage
  • action="read"
  • source="#ExpandPath( './100x100.gif' )#"
  • name="objImage"
  • />
  •  
  • <!--- Resize image. --->
  • <cfset ImageResize(
  • objImage,
  • 200,
  • 200
  • ) />
  •  
  • <!--- Try to write the new image to disk. --->
  • <cftry>
  •  
  • <cfset ImageWrite(
  • objImage,
  • ExpandPath( "./200x200.gif" )
  • ) />
  •  
  • <cfcatch>
  •  
  • <!--- Dump out error. --->
  • <cfdump
  • var="#CFCATCH#"
  • label="ImageWrite() Error"
  • />
  •  
  • </cfcatch>
  • </cftry>

I started to narrow down the things that could be causing it. I replaced the ImageWrite() method with the CFImage write tag:

 Launch code in new window » Download code as text file »

  • <cfimage
  • action="write"
  • source="#objImage#"
  • destination="#ExpandPath( './200x200b.gif' )#"
  • />

... but this gets the same error. The only thing that would fix it was actually removing the ImageResize() method. But why? What's going on?

Previously, I stated that the image was a COMPLETELY transparent GIF. This means that it was a transparent canvas that didn't have a single colored pixel on it - nothing, not one piece of non-transparent image. That seems to be what is breaking it. If I place even a single 1x1 black square in the middle of the vast, transparent canvas, the code works perfectly fine. It seems that when ColdFusion 8 goes to resize a completely transparent canvas, something goes funny.

Seems like a bug to me.

Download Code Snippet ZIP File

Comments (8)  |  Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page



Adobe ColdFusion 8.0.1 Update - Helping Programmers To Be Signifanctly Less Girlie - Download ColdFusion 8 Update 8.0.1 Now.

Reader Comments

Hi,
I'm resizing a gif image having a transparent index using cfimage action="resize"... , and it looks like that index disappears once resized. May be this is part of the same bug, or may be I'm missing something here to conserve the index...

Posted by Gov on Aug 28, 2007 at 5:35 PM


Very interesting. Might be related.

Posted by Ben Nadel on Aug 28, 2007 at 5:46 PM


Well I was reviewing some issues on a project that will soon be in production. One of which I've titled "lost of transparency index on resizing gif image" and I came stright to your fantastic site while Googleing about it.
I've discovered your site just a couple of months ago when I just started to play with CF8 during Scorpio beta testings and I have to say, your site stands, together with CFjedi and Ben Forta on top 3 position of my favorite CF related bookmarks.
Thank you for sharing, and please continue the great work!

Posted by Gov on Aug 29, 2007 at 7:12 AM


@Gov,

That really means a lot to me to hear stuff like that :) Thank you very much for the kind words. Please do not hesitate to ask me anything if you get stuck somewhere.

Posted by Ben Nadel on Aug 29, 2007 at 7:16 AM


The imageresize has a additional bug:
If you resize a jpg of 443/600 (w/height) to new 73px height, you will get an image of 72 px !
the imagescaletofit does the same result.

Seams to be a rounding problem.
Actual the imageresize and imagescaletofit - functions aren´t useful.

hope for a hotfix on that and a bad problem on captcha - creations.

Posted by christian Küpers on Feb 24, 2008 at 5:31 PM


Christian, I'm having a similar problem. When using ImageResize it sometimes is 1px less than what I want it to be (or tell it to be for that matter).

You said they weren't useful, is there another solution?

Thanks

Posted by Kevin on Mar 4, 2008 at 2:47 PM


I now calculate the whole measurements by myself. Then do a normal imageresize; so it´s possible to get an image of correct measurements...

A bit ugly; the CF-documentation is also not correct; when you call the function with a string ("") as width or height you get an error message.

Posted by Christian Küpers on Mar 6, 2008 at 8:53 AM


I also noticed that when you resize a transparent gif you lose transparency, does this happen for you?

<code>
<cfimage action="resize" destination="thumbnail.gif" height="25%" overwrite="true" source="myLargeImage.gif" width="25%">
</code>

Posted by Joe Gautreau on Jun 25, 2008 at 6:26 PM


Post Comment  |  Ask Ben


Home   |   Web Log   |   ColdFusion   |   Projects   |   Resume   |   Job Form   |   Search   |   Contact
Epicenter Consulting - Custom Software Solutions for Business Evolution HostMySite.com - The Leader In ColdFusion Hosting