Thursday, May 26, 2011

Coldfusion: Slow ImageResize problem SOLVED

Sometimes, the built in Coldfusion Image functions can take a very long time to resize a jpeg image, like 20-30 minutes.

This is caused by ICC colour profiles, which really should be supported by an Adobe Product.

The quick solution is to use Imagemagick to strip out the ICC colour profile.

It's also a good idea to force the RGB colour space, as CMYK is also not handled.

C:\Program Files (x86)\ImageMagick-6.7.0-Q16\convert.exe
src_with_icc_profile.jpeg -colorspace rgb +profile 'icc' icc_stripped.jpeg

You can also use identify.exe with the -verbose option to detect ICC profiles, although it is a bit slow, 2-3s.

8 comments:

James Moberg said...

I thought using the sRGB color space would be better after reading this article regarding PDF generation.
http://coldfused.blogspot.com/2007/12/images-and-cfdocument-performance.html

Converting to sRGB may take longer (my images were already RGB and conversion was 3 seconds versus 11). I didn't notice any PDF generation performance differences between using RGB or sRGB. ImageMagick identify.exe also identified both color profiles as "RGB" & didn't make any distinction between the two.

You can also use ColdFusion to get the color space, but I believe it still fails on CMYK images.
http://www.coldfusionjedi.com/index.cfm/2009/6/8/Converting-the-color-space-of-an-image-for-PDF-consumption

I've been using isImageFile() so that I don't read CMYK images and get a CF error, but that can be slow too (2-3 seconds per 3mb image).

Jeff said...

You can also just -strip to remove all color profiles. Without specifying which one. CMYK to RGB does affect the coloring though.

Here are my code examples :

http://www.digitalrewind.com/post.cfm/cfimage-cmyk-workaround-rgb

Jeff said...

One more to to speed up the identify :

identify -verbose -size 64x64 your.jpg

The size options loads a small version into memory instead of the whole thing for large files. Still gives you the same info.

As far as my tests go all versions of ACF fail on CMYKs

Zac Spitzer said...

Cheers Jeff, thanks for the pointers!

I have filed this issue on the ugly flash adobe bug tracker for CF

Zac Spitzer said...

Update: I have been contacted by the Adobe Coldfusion dev team and they are investigating this problem

if you have any good sample images can post links to the images against the bug tracker?

Doug said...

Hi Zac -

If you are still in touch with the Adobe CF Dev Team, and need examples or more information to provide them regarding the slowness with the ImageResize option, I would like to help out however I can.

Thanks,

Doug

Zac Spitzer said...

Hey Doug,

I'd suggest dropping a comment on the bug tracker

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=86916

Charlie Arehart said...

No one's mentioned here the possibility that the resize speed might be improved by changing the interpolation value (from the default of "highestquality" to something else, perhaps even 'highestperformance".) It can make a big difference in speed, with perhaps no perceptible difference in image quality (test for yourself).

One challenge is that changing this is not supported in CFIMAGE until CF10, but in CF8 and 9 you can change to using the imageresize function, which supports changing the interpolation as its 4th argument.

I discuss this in more detail in a blog entry here: http://www.carehart.org/blog/client/index.cfm/2012/5/28/cf_image_resizing_problem_and_solution.

I do realize that some resize problems are due to CMYK issues, like James mentions here, and in fact he adds some discussion on that matter as comments on my entry. Adobe says they addressed this some in CF10 also, but if anyone has an example for them, they'd want to address is if possible.

Still, to Zac's original entry here, I just wanted to make sure that folks having resize performance problems are at least aware of this option. It's helped a lot of people when I've been helping with image resize performance problems. Hope it's helpful.