Skip to main content
Known Participant
April 12, 2011
Question

CFIMAGE error "Numbers of source Raster bands and source color space components do not match"

  • April 12, 2011
  • 2 replies
  • 12783 views

I keep on getting this error when trying to upload a .JPG file. This error is not present for all jpegs, just for some of them.

I am running CF 9 on a Windows 64-bit server.

Any suggestions on how to modify cfimage tag or workaround this?

Thank you!

    This topic has been closed for replies.

    2 replies

    Participant
    October 3, 2012

    This error seems to occur when a JPG is encoded in grayscale, on CF9 (at least, that's what I found to be the case when I received the error).

    The workaround is to read the image file as a binary object:

    <cffile action="readBinary" file="...source to image file..." variable="objBinary" />

    <cfset objImage = ImageNew(objBinary) />

    ... other code ...

    <cfset ImageWrite(objImage, "...destination file...") />

    Hope this helps someone else out.

    -Dain

    Known Participant
    October 4, 2012

    Dain,

    I think what you proposed solves for some file read issues but not the CYMK issue. I don't have time to try but you can try the image attached to Sasha365 post above to see if it hits the same problem. Our image upload handling routine now has many CFCATCHes, first level will try the readBinary approach again, then if fail to CFCATCH will check for 'bandOffset' or 'raster' then launch the EXE.

    Let me know if your code also works for CMYK in CF8/9 though I doubt it will, because the old code fundamentally does not handle CMYK. In CF10 it is supposed to handle CMYK properly and it is in the list of new features (not tried it yet though, too busy).

    Regards,

    Andrew

    Participant
    October 4, 2012

    Andrew,

    Correct, this does nothing for the CMYK issue, which is a separate issue entirely, more to do with the underlying JRE version (there are documented bugs on Oracle's site about this). For these, I just alert the use to re-save as RGB since updating Java is not something I want to entertain on my production servers at this point.

    -Dain

    Sasha365iAuthor
    Known Participant
    April 13, 2011

    can't believe nobody has run into this.

    is anyone using CF 9 out there?

    Inspiring
    April 13, 2011

    Using CF9?  Sure.  Using CF for image manipulation?  Nup.  Also your post is quite ill-defined.  You say in the ehading it's a problem with CFIMAGE, but then you say it's a problem when you upload an image.  I doubt it's anything to do with uploading the image (which is done by the web wever, not CF, anyhow).

    However I have used Google, and googling your error suggests the file is quite possibly malformed.

    Are the images you're having problems with created / manipulated with a specific application?

    Can you post some code and the image you're having problems with?  That way people won't just be looking blankly at your post going "WTF?"

    --

    Adam

    Sasha365iAuthor
    Known Participant
    April 13, 2011

    Adam, thanks for your reply.

    The highlighted line of code throws an error in CF:

    "Numbers of source Raster bands and source color space components do not match"

    Here is the photo that creates the problem:

    I do not know how this photo is taken, other than it was successfully uploaded by a user using cffile on Coldfusion MX server running on Windows 32-bit.

    <cfset myoldimage = #cffile.ServerFile#>
      <cfset myextsn = #cffile.serverFileExt#>
      <cfset mynewimage = "#Form.fullname#" & "." & "#Variables.myextsn#">

    <cfset tempfile="C:\Inetpub\wwwroot\images\" & '#Form.photo#' & ".jpg">
    <cfimage source="C:\Inetpub\wwwroot\images\#Variables.myoldimage#" action="convert"

        destination="#tempfile#">
          <cffile action="delete"
          file="C:\Inetpub\wwwroot\images\#Variables.myoldimage#">

    <cfset myImage=ImageNew("#tempfile#")>
    <cfset ImageResize(myImage,"250","")>
    <!--- Save the modified image to a file. --->
    <cfimage source="#myImage#" action="write" destination="#tempfile#" overwrite="yes">

    Thanks for your help.