Trouble converting png to jpg

275 views
Skip to first unread message

Michael Wood

unread,
Nov 1, 2015, 5:23:25 PM11/1/15
to Lucee
I'm new to Lucee. I've installed Lucee 4.5.1.022 on Linux and it's worked great so far but now I can't seem get a simple image file conversion to work.

<cfimage action="convert" source="mytest.png" destination="mytest.jpg"> returns the exception message "Metadata components != number of destination bands".

This works just fine in ACF. Am I not using the cfimage tag correctly in Lucee?

Andrew Dixon

unread,
Nov 1, 2015, 5:28:35 PM11/1/15
to lu...@googlegroups.com
Hi Michael,

The syntax looks correct, maybe it is the particular PNG image you are attempting to convert. Have you tried other PNG's? That error almost reads like the source file is corrupt somehow.

Kind regards,

Andrew

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/7b298e4c-e079-4059-9264-1cda8a03ac13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Wood

unread,
Nov 1, 2015, 8:02:34 PM11/1/15
to Lucee
Hello Andrew and thank you for replying.

I've spent a frustrating afternoon trying to sort this out. It seemed unlikely that this wouldn't work in Lucee but you never know...

Anyway I've taken some new photos and converted them to PNG's using Photoshop and the CFImage conversion back to JPG images works on the new images. Also of note it seems like any editing of the images in photoshop (cropping, etc) causes this issue.

I have a folder full of "test" images that I've collected over time and all the PNG images fail this conversion. This fooled me. They convert okay on an Windows based ACF server. But now I'm thinking there may be something else going on, perhaps OS related.

I'll keep digging for the actual cause and/or work-around.

Thank you again,

Michael

Paul Klinkenberg

unread,
Nov 3, 2015, 8:16:41 AM11/3/15
to lu...@googlegroups.com
Hi Michael,

This is a known issue, has been around for a long time.
It has to do with the underlying image manipulation jars, Lucee can't fix it, unless they start using a different library, for example Imagemagick.
This error, and two more, were enough reason for me and the company I worked for then, to start using Imagemagick instead of cfimage.

References: 

Even though ImageMagick can take some time to setup and understand, in the end it is worth it, imho.

Kind regards,

Paul Klinkenberg



Andrew Dixon

unread,
Nov 3, 2015, 1:32:30 PM11/3/15
to lu...@googlegroups.com
@Paul - Do you know if there is a bug logged in the bug tracker for this?

Kind regards,

Andrew

Paul Klinkenberg

unread,
Nov 3, 2015, 1:40:43 PM11/3/15
to lu...@googlegroups.com
Well... https://issues.jboss.org/browse/RAILO-1849

I don't know if it has been copied to the Lucee bug tracker.


--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Andrew Dixon

unread,
Nov 3, 2015, 1:51:48 PM11/3/15
to lu...@googlegroups.com
Hi,

Doesn't looks like it, so raised:


@Michael, looks like there is a work around in the comments.

Kind regards,

Andrew

Ryan Guill

unread,
Nov 4, 2015, 11:53:52 AM11/4/15
to Lucee
Paul, do you have any resources or information about how you work with imagemagick from lucee? do you call out through cfexecute or use something like jmagick? something else?

Paul Klinkenberg

unread,
Nov 4, 2015, 4:11:45 PM11/4/15
to lu...@googlegroups.com
Hi Ryan,

Here is a snippet of code on how to use it.

Kind regards, Paul Klinkenberg
var convertCmd = createObject("java", "org.im4java.core.ConvertCmd").init();
/* search path: where imagemagick is located (on linux, it can usually be found in path) */
convertCmd.setSearchPath("C:\ImageMagick-6.7.9-Q16\");

var operation = createObject("java", "org.im4java.core.IMOperation").init();
operation.addImage([arguments.image]);

operation.colorspace("RGB");

/* for JPG, add the quality */
if (newExt eq "jpg")
{
var quality = structKeyExists(arguments, "quality") ? arguments.quality : "";
if (not isNumeric(quality) or quality eq 0)
{
quality = variables.defaultJPGQuality;
} else if (quality lt 1)
{
quality = quality*100;
}
operation.quality(javaCast('java.lang.Double', quality));
}

// Support for a transparency fillcolor
if (structKeyExists(size, "background"))
{
operation.background(size.background);
operation.flatten();
}

/* rotation? */
if (doRotate)
{
operation.rotate(toString(size.rotation));
}

/* crop? */
if (doCrop)
{
operation.crop(arguments.width, arguments.height, 0, 0);
/* resize */
} else {
operation.resize(JavaCast('int', arguments.width), javaCast('int', arguments.height));
}
/* grayscale ? */
if (structKeyExists(arguments, "grayscale") and arguments.grayscale eq true)
{
operation.colorspace("gray");
} else
{
operation.colorspace("sRGB");
}

// save the new file to a temp location
var tempImagePath = getTempDirectory() & createUUID() & ".#newExt#";
operation.addImage([tempImagePath]);

convertCmd.run(operation, []);

return tempImagePath;



-- 
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
--- 
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

online...@gmail.com

unread,
Dec 15, 2016, 11:48:36 AM12/15/16
to Lucee
Hi all, I'm on Lucee 5.x (latest stable build) and am getting this error:

https://luceeserver.atlassian.net/browse/LDEV-392 (CFIMAGE results in out of bands with PNG files)

Anyone @Lucee have an update on why this is happening and why this bug hasn't been fixed yet?

Hope to hear from @Lucee on this.

Thnx.

Sebastiaan

Op zondag 1 november 2015 23:23:25 UTC+1 schreef Michael Wood:

online...@gmail.com

unread,
Dec 15, 2016, 11:50:58 AM12/15/16
to Lucee
BTW, I'm on Windows 10, same error on Windows Server machines. If this is a Java library issue, how to program around this without resorting to other Java-libs. Want to stay as standard as possible for this customer. All extras are troublesome ;-)

Op donderdag 15 december 2016 17:48:36 UTC+1 schreef online...@gmail.com:

online...@gmail.com

unread,
Dec 15, 2016, 11:52:27 AM12/15/16
to Lucee
Hi Paul, isn't it possible to add other image-manipulation JAR's to Lucee, like if this fails, please use the other one? Sebastiaan

Op dinsdag 3 november 2015 14:16:41 UTC+1 schreef Paul Klinkenberg:

online...@gmail.com

unread,
Dec 15, 2016, 11:53:46 AM12/15/16
to Lucee
I guess that new issue doubles for this one: https://luceeserver.atlassian.net/browse/LDEV-392

Op dinsdag 3 november 2015 19:51:48 UTC+1 schreef Andrew Dixon:

Mark Drew

unread,
Dec 15, 2016, 11:57:10 AM12/15/16
to lu...@googlegroups.com
To be honest I would just use something like http://cloudinary.com/ instead. Much easier. 

Mark Drew


develop • deploy • deliver

online...@gmail.com

unread,
Dec 15, 2016, 12:04:44 PM12/15/16
to Lucee
@Mark - how is that a solution to a simple cfimage convert functionality? Here the issue is a user that can upload his/her picture of any said format (JPG, JPEG, GIF, PNG) and then we convert it to a JPG for them so it fits into our system. All's well until a PNG is uploaded. Should't that be fixed then?

Op donderdag 15 december 2016 17:57:10 UTC+1 schreef Mark Drew:

Denard Springle

unread,
Dec 16, 2016, 6:34:31 PM12/16/16
to Lucee
Yes it should be fixed, of course. 

I think Mark's suggestion is that services like Cloudinary are a workaround to the problem and offer much more in terms of capabilities than cfimage does - perhaps leading to enhanced capabilities for your own site and your own users.

That said, I convert everything to PNG in my applications and then run them through the TinyPNG API for both scaling and for minimizing the file size - but then I do a lot of responsive work for mobile and want the smallest possible files to conserve bandwidth :)

I haven't used Cloudinary myself, but Sean Daniels has a Gist of an API wrapper for it (https://gist.github.com/sjdaniels/a31bbd9192cd28e48fcf). and if you want to use TinyPNG (also supports JPEG fwiw), I have an API wrapper for that (https://github.com/ddspringle/TinyPngCFML)

HTH

-- Denny

Jean Moniatte

unread,
Dec 16, 2016, 10:49:04 PM12/16/16
to lu...@googlegroups.com

On Fri, Dec 16, 2016 at 3:34 PM, Denard Springle <denard....@gmail.com> wrote:
I think Mark's suggestion is that services like Cloudinary are a workaround to the problem and offer much more in terms of capabilities than cfimage does - perhaps leading to enhanced capabilities for your own site and your own users.

Until that service is offline or does not exist anymore.

Denard Springle

unread,
Dec 18, 2016, 5:53:16 AM12/18/16
to Lucee
In which case there will be 13 other ones to replace it and you're guaranteed more days of employment. Nothing lasts forever, but not embracing the technology that does exist because it might some day disappear doesn't make much sense either. Especially and if only as a temporary workaround to a problem that is customer affecting in the now as a fallback to cfimage. That said, I don't know enough about Cloudinary to speak to its reliability or longevity... but hey, it's got cloud in the name... that's something :P

-- Denny  
Reply all
Reply to author
Forward
0 new messages