Skip to main content
November 7, 2008
Answered

Strange imageWrite() Behaviour on Specific JPG files

  • November 7, 2008
  • 4 replies
  • 712 views
Hi,

I have written an application to upload files and process them etc. Everything works fine.

However, certain JPG files cause an error in the imageWrite() function where I try to set the image quality.

An exception occured 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.io.FileNotFoundException: C:\ColdFusion8\wwwroot\cms\skylitecms\cmsFiles\P61901721.JPG (The system cannot find the file specified)

I have seen this error around the Internet, but that was concerning transparent GIF files.

I can confirm that the directory DOES exist and other images save just fine. I noticed oddly enough that the images erroring were images I had taken with my digital camera - ALL of them error! But, if I open the image up in FireWorks, export it as a JPG (like it is already), then upload THAT new JPG file, it works.

So the problem seems to be specific to these JPG files, but I can't understand why. I CFDUMP the upload from CFFILE and all of the variables seem normal - in particular, the "FILEWASSAVED" returned from the struct in the CFDUMP says "YES" but when I go to look in the folder it's not there....which is presumably why the imageWrite() fails?

This is very odd.

Please take a look at both image files and see if you have any problems with them.

The image that errors:
www.unibands.co.uk/P6190172.jpg

The re-exported image that works:
www.unibands.co.uk/newP6190172.jpg

Any help would be greatly appreciated. Apologies for the size of the images, they're quite large but I wanted to change as little as possible and didn't want to tamper with the original incase it changed anything. And yes, that is my dog!! :)

Many thanks in advance for your help.

Mikey.
    This topic has been closed for replies.
    Correct answer -__cfSearching__-
    Kapitaine,

    What version are you running? There were some image related hotfixes. One of which had to do with locked files.

    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402604
    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403411&sliceId=1

    4 replies

    November 10, 2008
    Hi BKBK,

    I tried your example, and yes, it does indeed seem to work. This is very strange. I would argue that it's probably down to my coding ability, and that I may be doing something very wrong...on the other hand though, if this works for every other image not taken by this camera, then how can it? I'm at my wits end with this...I have tried every combination possible.

    Hmm. Because my code is long and complex I wouldn't want to post it all here but I will copy and paste below the main part giving me grief. If you or anyone else can see problems with this it would be greatly appreciated.

    As I said earlier, this code works, but not with these images. There's something else at play here.

    Code
    -----------------------------

    <cfset myImage = ImageNew(variables.imagePath) />
    <cfset imageSetAntialiasing(myImage,"on") />

    <cfif val(arguments.imageWidth) and val(arguments.imageHeight) gt 0>
    <cfset imageResize(myImage,val(arguments.imageWidth),val(arguments.imageHeight),"lanczos",1) />
    <cfelseif val(arguments.imageWidth) gt 0 and val(arguments.imageHeight) lte 0>
    <cfset imageResize(myImage,val(arguments.imageWidth),"","lanczos",1) />
    <cfelseif val(arguments.imageWidth) lte 0 and val(arguments.imageHeight) gt 0>
    <cfset imageResize(myImage,"",val(arguments.imageHeight),"lanczos",1) />
    </cfif>

    <!--- This is the line that errors, indeed any line that uses cfimage to write or imageWrite. I changed it to a tag recently to see if it made any difference --->
    <cfimage action="write" destination="#variables.imagePath#" source="#myImage#" quality="#val(arguments.imageQuality)#" overwrite="true" />

    <cfif val(arguments.imageBlur) neq 0>
    <cfset imageBlur(myImage,val(arguments.imageBlur)) />
    </cfif>

    <cfset imageRotate(myImage,val(arguments.imageRotate)) />

    <cfif arguments.imageGreyscale eq "yes">
    <cfset imageGrayscale(myImage) />
    </cfif>

    <cfif trim(arguments.imageFormat) neq "">

    <cfset variables.newFormat = uploadImage.serverDirectory & "\" & uploadImage.clientFileName & "." & arguments.imageFormat />

    <cfimage action="write" source="#myImage#" destination="#variables.newFormat#" overwrite="yes" />
    <cfimage action="read" source="#variables.newFormat#" name="getUploadedImage" />

    <cfif fileExists(variables.imagePath) eq "yes">
    <cffile action="delete" file="#variables.imagePath#" />
    </cfif>

    <cfelse>

    <cfimage action="write" source="#myImage#" destination="#variables.imagePath#" overwrite="yes" />
    <cfimage action="read" source="#variables.imagePath#" name="getUploadedImage" />

    </cfif>


    Mikey.
    -__cfSearching__-Correct answer
    Inspiring
    November 10, 2008
    Kapitaine,

    What version are you running? There were some image related hotfixes. One of which had to do with locked files.

    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402604
    http://kb.adobe.com/selfservice/viewContent.do?externalId=kb403411&sliceId=1
    November 11, 2008
    Hi CFSEARCHING,

    This hot fix works great! The image is now processing correctly. Many thanks for the heads up!!

    Thanks to everyone else also who helped in the assistance with this.

    Happy coding! :)

    Mikey.
    BKBK
    Community Expert
    Community Expert
    November 10, 2008
    I wrote:
    Looks like a case of vendor-locking. Do you happen to have an Olympus camera? And how did I know?

    Download EditPad Lite. It is free. Use it to open both files, that is, to display the binary content as characters. Search for Olympus. You will find that there are numerous occurrences of the text 'Olympus Digital Camera' in the file that has been giving you problems. Is that a coincidence, I wonder.


    But, then again, I thought it's very unlikely that a reputable vendor like Olympus would take the risk to frustrate users. So, let's start with the hypothesis that the error isn't caused by vendor-locking.

    I ran the following code as a proof of concept:
    <cfset kapitaine_friend = ImageNew(" http://www.unibands.co.uk/P6190172.jpg")>
    <!--- <cfset kapitaine_friend = ImageNew(" http://www.unibands.co.uk/newP6190172.jpg")> --->
    <!--- Convert image from JPG to PNG format. --->
    <cfset ImageWrite(kapitaine_friend,"kapitaine_friend.png")>
    <!--- Display PNG image. --->
    <img src="kapitaine_friend.png">

    There were no problems with P6190172.jpg or with newP6190172.jpg. It seems to rule out Coldfusion as culprit.

    Take another look at the error-message, java.io.FileNotFoundException: C:\ColdFusion8\wwwroot\cms\skylitecms\cmsFiles\P61901721.JPG (The system cannot find the file specified). It could be a simple case of case-sensitivity. Have you tested it with lower-case extension, that is, P61901721.jpg?


    Inspiring
    November 10, 2008
    Can you put a simple reproduceable case here (ie: some code). I can make
    sure it gets in front of the appropriate people.

    --
    Adam
    BKBK
    Community Expert
    Community Expert
    November 8, 2008
    Looks like a case of vendor-locking. Do you happen to have an Olympus camera? And how did I know?

    Download EditPad Lite. It is free. Use it to open both files, that is, to display the binary content as characters. Search for Olympus. You will find that there are numerous occurrences of the text 'Olympus Digital Camera' in the file that has been giving you problems. Is that a coincidence, I wonder.

    November 9, 2008
    Hi BKBK,

    I haven't checked this yet, but I do indeed have an Olympus camera...the darn buggers! Why would they do such a thing? Is there any way to get around this? Are there other companies out there doing a similar locking?

    I can upload these fine to other sites like Facebook etc so there must be a solution out there.

    Many thanks for your help!

    Mikey.