• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Bug with ImageResize/ImageScaleToFit functions and cfimage tag

New Here ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

We’re experiencing an important issue on our CF11 server: when we try to resize an image, it changes its appearance to a negative/posterized image (e.g. see attached images). We tried both with ImageResize/ImageScaleToFit functions and cfimage tag, and we also made several tests by changing the interpolation and the other options value.

Further more, we have 4 different CF instances on the same server, with pretty similar configurations and with exactly the same Java version (1.8) and libraries, but we have this issue only on one of them and it start to appear few weeks after the previous reboot, so we need to restart again the instance to avoid the problem.

Can you please provide a solution or suggest any other way to solve this issue?

original-image.png

resized-image.png

Views

964

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Hello, ImageLine,

Could you please provide your code, and information on the images (ie, format, color coding, etc.)?

V/r,

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

We made several tests both with jpg and png images and different color profiles, the attached image is a sRGB png.

Here is the code:

<!--- read image file from disk --->

<cfset imageObject = ImageRead("#imgPath##newImg#")>

<!--- set image antialiasing and resize --->

<cfset ImageSetAntialiasing(imageObject,"on") />

<cfset ImageScaleToFit(imageObject,imgMaxW,imgMaxH,"mediumQuality") />

<!--- overwrite image to disk --->

<cfset ImageWrite(imageObject,"#imgPath##newImg#",true) />

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2018 Mar 11, 2018

Copy link to clipboard

Copied

ImageLine  wrote

<!--- overwrite image to disk --->

<cfset ImageWrite(imageObject,"#imgPath##newImg#",true) />

Two suggestions that may or may not have anything to do with the behaviour you observe, but are worth testing:

add quality as the third attribute, plus a new name for the new file

<cfset imageWrite(imageObject,"#imgPath##newImg2#","0.75",true) />

For example, if the original image is called original-image.png, then define newImg2 to end in /image-copy.png.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

We stopped having image performance (and conversion) issues when we shifted all of our image manipulations to use GraphicsMagick.  It's a free library and we use CFExecute to pass the image path and instructions to the portable EXE file.  In our test, we've found that it's faster than Java, uses less RAM (or doesn't mess with the Java Heap) & the resultant file sizes are generally smaller.  It also supports more image formats than CFImage or Java.  We host many websites and process images for both photographer & MLS.

If interested, here's a screenshot of a series of tests & comparison times when using the PNG image that you provided.  (NOTE: I think the Adobe forums may have reduced the size of your original image.

CFForum_2451710.png - Box

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

Thanks Jamo, we've already heard about GraphicsMagick, but we'd like to solve the issue within the standard CF code

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

No problem... I respect that.

We desired consistent graphics conversion & better performance when using ColdFusion 8-2016 as well as have the ability to process images in the background without impacting ColdFusion, heap/RAM or consuming any CF threads.  We would prefer to pursue a CF-only solution, but we continued to encounter bugs & processing differences in newer versions of ColdFusion.  GM also provided additional transformation & conversion features that aren't available in CF (or required multiple steps in CF.)

In case you are curious, here's how to perform the same image transformation using GraphicsMagick (based on best practices that we've identified).  You can do this via the command line or use CFExecute. (NOTE: If using CFExecute, you'll need to use double quotations.)

Convert -colorspace rgb -strip -filter Lanczos -auto-orient -density 72x72 "#ImagePath#" -resize "#imgMaxW#x#imgMaxH#>" -interlace Line -quality 90 +profile "*" "#ImagePath#"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2018 Mar 11, 2018

Copy link to clipboard

Copied

LATEST

As an alternative to giving the new file a new name, keep the same name, but use locks.

<cflock scope="Application" timeout="10" type="readOnly">    

    <cfset imageObject = ImageRead("#imgPath##newImg#")>

</cflock>

<cflock scope="Application" timeout="10" type="exclusive">    

    <!--- set image antialiasing and resize --->

    <cfset ImageSetAntialiasing(imageObject,"on") />

   

    <cfset ImageScaleToFit(imageObject,imgMaxW,imgMaxH,"mediumQuality") />

   

    <!--- overwrite image to disk --->

    <cfset ImageWrite(imageObject,"#imgPath##newImg#",true) />

</cflock>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

I would think that, since it happens only on one of your 4 equally configured CF11 servers, that it may not be a "bug" in CF.

Rather, I would suspect the "difference" could be that the failing one had an error during the process of applying an update. I see it often and have blogged on it (including how to check, and fix things) here:

How to solve common problems with applying ColdFusion updates (in 10 and above)


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2018 Mar 11, 2018

Copy link to clipboard

Copied

Image line, did you ever solve this? Did my suggestion of a possible update bug help, since this was on some but not all of your servers?


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation