Skip to main content
Participant
September 23, 2009
Question

Image Manipulation is making green and pink thumbnails

  • September 23, 2009
  • 1 reply
  • 996 views

Using the coldfusion 8 image manipulation we are getting thumbnails that the colors are all green and pink.  This seems to only affect the thumbnails and not the larger resized images.  See screenshot for example.  Any ideas why this is happening or how to fix it?

The functions being used are ImageWrite and ImageScaleToFit.

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 23, 2009

    Can you provide the code you're using, as well as attaching a sample source image to run the code on?

    --

    Adam

    Participant
    September 24, 2009

    <!--- Set some defaults used by each image type, unless you override them --->
    <cfparam name="jpgQuality" default=".8" />
    <cfparam name="defaultInterpolation" default="bicubic" />
    <cfparam name="defaultBackground" default="black" />

    <!--- Set values for each image type --->
    <cfparam name="thumbMaxWidth" default="" />  <!--- leave blank to allow any width (forced to size by height) --->
    <cfparam name="thumbMaxHeight" default="60" /> <!--- leave blank to allow any height (forced to size by width, above) --->
    <cfparam name="thumbQuality" default="1" />  <!--- number from 0 - 1, 1 being the best --->
    <cfparam name="thumbFixedSize" default="false" />  <!--- you MUST set both MaxWidth & MaxHeight to use FixedSize --->
    <cfparam name="thumbBackground" default="#defaultBackground#" />  <!--- color of background if fixed size is used --->
    <cfparam name="thumbInterpolation" default="#defaultInterpolation#" />  <!--- Interpolation method used for resizing (HUGE performance hit depending on what is used) --->
    <cfparam name="normalMaxWidth" default="476" />
    <cfparam name="normalMaxHeight" default="324" />
    <cfparam name="normalQuality" default="#jpgQuality#" />
    <cfparam name="normalFixedSize" default="true" />
    <cfparam name="normalBackground" default="#defaultBackground#" />
    <cfparam name="normalInterpolation" default="#defaultInterpolation#" />
    <cfparam name="zoomMaxWidth" default="670" />
    <cfparam name="zoomMaxHeight" default="380" />
    <cfparam name="zoomQuality" default="#jpgQuality#" />
    <cfparam name="zoomFixedSize" default="true" />
    <cfparam name="zoomBackground" default="#defaultBackground#" />
    <cfparam name="zoomInterpolation" default="#defaultInterpolation#" />


    <!--- Set values for folder paths and the watermark image --->
    <cfparam name="originalFolder" default="path to folder for original images" />
    <cfparam name="thumbFolder" default="path to folder for thumbnail images" />
    <cfparam name="normalFolder" default="path to folder for large images" />
    <cfparam name="zoomFolder" default="path to folder for large resized images" />
    <cfparam name="watermarkImage" default="" />
    <cfparam name="wmXPosition" default="50" />  <!--- value is a number from 0 - 100, 50 = centered --->
    <cfparam name="wmYPosition" default="65" />

    <cffunction name="genWatermarkImage">
        <cfargument name="ImageFile" required="true" />
        <cfargument name="MaxWidth" required="true" />
        <cfargument name="MaxHeight" required="true" />
        <cfargument name="StorePath" required="true" />
        <cfargument name="FixedSize" required="true" type="Boolean" />
        <cfargument name="Background" required="true" />
        <cfargument name="Quality" required="true" />
        <cfargument name="Interpolation" required="true" />
        <cfargument name="AddWatermark" required="true" type="Boolean" />
        <cfif IsImageFile(originalFolder & ImageFile)>
            <cfset original = ImageNew(originalFolder & ImageFile) />
            <cfset originalHeight = ImageGetHeight(original) />
            <cfset originalWidth = ImageGetWidth(original) />
            <cfset outfile = StorePath & ImageFile />
            <cfset watermark = ImageNew(watermarkImage) />
            <cfset ImageScaleToFit(original,MaxWidth,MaxHeight,Interpolation) />
            <cfset new_w = ImageGetWidth(original) />
            <cfset new_h = ImageGetHeight(original) />
            <cfif FixedSize>
                <cfset normal = ImageNew("",MaxWidth,MaxHeight,"rgb",Background) />
                <cfset ImagePaste(normal,original,int((MaxWidth-new_w)/2),int((MaxHeight-new_h)/2)) />
                <cfif AddWatermark>
                    <cfset ImagePaste(normal,watermark,( int(ImageGetWidth(normal)) - int(ImageGetWidth(watermark)) -3),( int(ImageGetHeight(normal)) - int(ImageGetHeight(watermark)) -3) )/>
                </cfif>
                <cfset ImageWrite(normal,outfile,Quality) />
            <cfelse>
                <cfif AddWatermark>
                    <cfset ImagePaste(original,watermark,( int(ImageGetWidth(normal)) - int(ImageGetWidth(watermark)) -3), (int(ImageGetHeight(normal)) - int(ImageGetHeight(watermark)) -3) )/>
                </cfif>
                <cfset ImageWrite(original,outfile,Quality) />
            </cfif>
        <cfelse>
            <cfreturn "Image file not an image!" />
        </cfif>
    </cffunction>

    <cfset thumbError = genWatermarkImage(Filename ,thumbMaxWidth,thumbMaxHeight,thumbFolder,thumbFixedSize,thumbBackground,thumbQuality,thumbInterpolation,"false") />

    <!---One of the images this happened to is attached.  This problem doesn't happen everytime but when it does it is a large group of photos.--->

    Inspiring
    September 30, 2009

    Hmmm.

    It's probably no consolation to you but:

    a) I get the same results (tweaking your code slightly so that it runs);

    b) it's fixed in CF9.  I cannot find which specific issue it was that fixed it, but there were a number of image-related bugs fixed.

    One thing.

    Your steps to reproduce had an awful lot of unnecessary code, making it much more difficult to assess what could be contributing to the problem.

    This code demonstrates the issue far more succinctly:

    <cfset sDir = expandPath('./')>
    <cfset sSrcImg = sDir & "originalImage.jpg">
    <cfset sDestImg = sDir & "thumbImage.jpg">

    <cfset imgOriginal = imageNew(sSrcImg)>
    <cfset imageScaleToFit(imgOriginal, "", 60, "bicubic")>
    <cfset imageWrite(imgOriginal, sDestImg, .8)>

    That's six lines of code (indeed it could be as few as three), rather than 80-odd lines of code.

    When providing steps to reproduce: keeping it as short as possible with the fewest moving parts is always something to aim for.

    I'm not sure what to suggest by way of remedial action though, unfortunately.  I guess you could install a CF9 instance and use its new exposed CF service layer (one of which is the image processing) to use the CF9 instance to remotely do your thumbnails for you?  I'm not sure how viable a suggestion that is.

    --

    Adam