How do you use jmagick or im4java in Coldfusion

1,326 views
Skip to first unread message

The Dude (Abides)

unread,
Nov 6, 2013, 5:04:38 AM11/6/13
to ra...@googlegroups.com
Hi, I'm looking to move on from cfimage to imagemagick using either jmagick or im4java in railo cfml apps. Main reason being for performance and image quality and ability to get image dpi.

Does anyone here have any experience on how to do this in a Linux environment, the few search results detail a windows environment.

I've installed imagemagick and jmagick on the linux server, but not clear how to actually use it in cfml.

Mark Mandel

unread,
Nov 6, 2013, 6:14:30 AM11/6/13
to ra...@googlegroups.com

Why not just call imagemagick directly with cfexecute?

Mark

Sent from my mobile doohickey

--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/railo/aaf2da5c-1879-4c5c-b5dc-a90c70294ae5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Bruce Kirkpatrick

unread,
Nov 6, 2013, 2:57:11 PM11/6/13
to ra...@googlegroups.com
I use cfexecute with absolute path to the imagemagick files - works great with similar performance for just a few simple commands like info / crop / resize.    If you need to do many operations on a file, you probably need to look at using PHP.   Like I made a whitespace trimming + resize + crop feature with php gd library functions.   It would be slower using many cfexecute operations.    This is why using java libraries would be superior since you could operate on the data in memory in complex ways.  

The color profile bug with some jpeg files is why I can't use <cfimage>.

It might be possible to put some of the jmagick jar files in /opt/railo/lib/railo-server/context/lib or load them with the absolute path the the 3rd argument of createobject("java", "com.class....", "/path/to/jmagick.jar");

The rest will require know how to write the Java according to the imagemagick docs.   I'd imagine building your code with a java IDE as a java command line app would be tremendously easier, and then see if you can migrate that to CFML code afterwards.   Or just make your own Java class that accepts simpler arguments to do the specific thing you want.    If you find success, consider posting your work on github, so that others don't have to struggle like you did!

AJ Mercer

unread,
Nov 6, 2013, 5:34:26 PM11/6/13
to ra...@googlegroups.com
on Windows machines, it is probably best to store 3rd Party JAR files in your own directory, and used path param in CreateObject, as Windows locks JAR files in the Railo lib requiring you to stop the engine if you want to update/remove the JAR.




--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.

For more options, visit https://groups.google.com/groups/opt_out.

Mark Mandel

unread,
Nov 6, 2013, 5:35:50 PM11/6/13
to ra...@googlegroups.com

On Thu, Nov 7, 2013 at 6:57 AM, Bruce Kirkpatrick <br...@farbeyondcode.com> wrote:
I use cfexecute with absolute path to the imagemagick files - works great with similar performance for just a few simple commands like info / crop / resize.    If you need to do many operations on a file, you probably need to look at using PHP.   Like I made a whitespace trimming + resize + crop feature with php gd library functions.   It would be slower using many cfexecute operations.    This is why using java libraries would be superior since you could operate on the data in memory in complex ways.  

Don't those libraries just wrap system calls to imagemagick? Why does PHP (and why specifically PHP btw?) make it better?

Mark

The Dude (Abides)

unread,
Nov 6, 2013, 5:50:30 PM11/6/13
to ra...@googlegroups.com
I'd like to use imagemagick on Linux Debian 7, so using cfexecute to run the imagemagick.exe file not an option.

Using jmagick as the layer between cfml and imagemagick seems the better approach, although I read somewhere you have to get the right version of jmagick and imagemagick as jmagick is always a version or 2 behind imagemagick.

Does anyone know how ImageCFC compares to imagemagick just for:

1. Image resizing performance
2. Image quality
3. Ability to define and set dpi

Its a shame the Efflare folks won't do a 64 bit version for Linux, that tag was awesome in user friendliness, quality and performance but time to say adios to Windows.

Bruce Kirkpatrick

unread,
Nov 6, 2013, 5:58:07 PM11/6/13
to ra...@googlegroups.com
php-simplest alternative dynamic language with the most free open source examples?

imagemagick has both command line and API library.  I would assume the library would not just call command lines internally, and it would operate inside a single process?  If not, that would be bad.

command line of imagemagick works cross platform - even debian.

Performance is similar when you do something like 80-90% jpeg quality, but cfimage and imagemagick both are optimal in terms of quality at different settings.  If you go for the highest quality, there is a huge drop in performance.

Igal @ getRailo.org

unread,
Nov 6, 2013, 6:58:39 PM11/6/13
to ra...@googlegroups.com
If not, that would be bad.
apparently it is bad.
--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.

For more options, visit https://groups.google.com/groups/opt_out.

-- 
Igal Sapir
Railo Core Developer
http://getRailo.org/

Bruce Kirkpatrick

unread,
Nov 6, 2013, 8:30:44 PM11/6/13
to ra...@googlegroups.com
It says JMagick uses Java Native Interface to map Java to the C api with a thin layer.  Sounds like the fastest way to interact with non-java code?

The other java projects also says JMagick is faster because of that.  They call the imagemagick api a "low level interface".

I don't know what the fastest image manipulation library is, but I'd bet JMagick is pretty darn quick compared to cfexecute of imagemagick if you were to do many API calls at once.  If not faster, it would at least use less memory and I/O not having to reload the file over and over.

Not sure what overhead is involved with JNI if any, but php may have less overhead with C based image manipulations since PHP is written with C++.

The Dude (Abides)

unread,
Nov 7, 2013, 2:59:09 AM11/7/13
to ra...@googlegroups.com
How about using Java.awt.image function directly in java itself bypassing cfimage or an imagemagick altogether?

Might that be a faster approach just for resizing, getting width, height, dpi?

The Dude (Abides)

unread,
Nov 7, 2013, 3:30:03 AM11/7/13
to ra...@googlegroups.com
How about the following as an option, seems to me accessing the jar in cfml it could be a good solution for performance and quality:

http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library/

imgscalr is an very simple and efficient (hardware accelerated) “best-practices” image-scaling library implemented in pure Java 2D; as of the 4.0 release imgscalr now includes a handful of other convenience image operations, all as easy to use as resize.

This library makes  uses of efficient Java2D scaling techniques advocated by the Java2D team which provides hardware accelerated operations on most platforms.

What Problem Does this Solve?

If you have ever wanted to quickly resize an image in Java you have probably noticed the following confusing things:

imgscalr addresses all these issues.

Benefits

  • 100% Java code based on Java2D, no native libraries to install
  • Java that works in “headless” environments without special environment variable settings; it just works.
  • Because there are no native libraries, you mitigate the risk of native libraries crashing the host VM (e.g. your app server) or thread-contention issues
  • Hardware accelerated on supported platforms (uses the optimized Java2D rendering pipeline)
  • Fast; not faster than a native-C solution, but still damn fast.
  • Simple, simple, simple. A handful of static, 1-word methods you can call. No complex configurations, managers, encoders/decoders or any other nonsense. imgscalr is not a “graphics library”, it is a set of the most commonly used graphic operations, optimized and ready to do your bidding.

Usage

The simplest use-case of the library for resizing an image is a single 2-argument method call:

BufferedImage thumbnail = Scalr.resize(image, 150);

In this use-case we pass the library our image and ask it to fit the image (while maintaing its original proportions) within a width and height of 150 pixels.

Alternatively, if we wanted some finer-grained control over how our image is scaled, quality used and possibly a light anti-aliasing filter to it (to make it look smoother) our method call would look something like this:

BufferedImage thumbnail =
  Scalr.resize(image, Scalr.Method.SPEED, Scalr.Mode.FIT_TO_WIDTH,
               150, 100, Scalr.OP_ANTIALIAS);

You can see that we a slew of knobs and levers to change when using the library. A few things worth noting are the Method and Mode enums defined on the Scalr class. These enums are used in conjunction with all of the resize methods.

Usability Tip: Java’s static imports makes using imgscalr a walk in the park, consider the following snippet of code to see how easy it becomes:

import static org.imgscalr.Scalr.*;
 
public static BufferedImage createThumbnail(BufferedImage img) {
  // Create quickly, then smooth and brighten it.
  img = resize(img, Method.SPEED, 125, OP_ANTIALIAS, OP_BRIGHTER);
 
  // Let's add a little border before we return result.
  return pad(img, 4);
}

Of course we could have inlined the resize directly inside of the pad call, but for readability I split them up; either way, you see how simple it is to use imgscalr in your projects.

There are a set of other operations we can do to our image, like rotating it, padding it, cropping it and so on.

By default imgscalr always honors the image’s original proportions above all else. If invalid target dimensions are passed in, imgscalr will re-calculate proper dimensions honoring the primary dimension of the image first (selected based on the image’s orientation). The only way to force imgscalr to resize (stretching if necessary) an image into a target bounding box is to use Scalr.Mode.FIT_EXACT.

Intended Audience

This library is intended for developers needing to quickly resize or manipulate images (using the correct or most optimal methods available in native Java) and move one with their lives.

imgscalr is general purpose and will work on any platform providing the base Java2D classes it uses. imgscalr was also written with web application’s in mind, possibly needing to generate thousands of thumbnails or previews from larger uploaded images.

This library is not meant to be a full-scale Java graphics library like JAI.

AJ Mercer

unread,
Nov 7, 2013, 5:22:18 AM11/7/13
to ra...@googlegroups.com
if you just want to resize an image, check out imageresize()

Railo has a lot of image functions



--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.

For more options, visit https://groups.google.com/groups/opt_out.



--

The Dude (Abides)

unread,
Nov 7, 2013, 6:29:25 AM11/7/13
to ra...@googlegroups.com
I ported from Windows/Imagecr3 to Linux/cfimage.

Most of the code is now refactored to cfimage and works fine with highest performance setting on imageresize.

cfimage tags are user friendly, I'm just trying to improve performance and image quality for a photo upload/resize intensive app, hence looking at imagemagick and java options. At highest quality cfimage performance is noticeably slower.

The other thing is I need dpi to approve an original artworkupload at 300 dpi so it can be printed and shipped.With the following code the dpi result is inconsistent, sometimes 0 and sometimes 96 on the test image.

<cfimage action="read"
                source="#application.filepath#/media/artistphotos/316.jpg"
                name="myImage" />

<cfoutput>
     #ImageGetEXIFMetaData(myImage).Xdensity#
</cfoutput>

So it seems best route for a more image intensive app is to look at other options like scalar, jai, jimage (imagemagick java wrapper) and imagej.
Reply all
Reply to author
Forward
0 new messages