Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java and GraphicsMagick -- Will it work?

I am considering using GraphicsMagick (http://www.graphicsmagick.org/) in a Java project. Does anyone have any experience with this? Suggestions on how to get started? It seems like there isn't a native Java library so it may be a little more difficult.

Thanks!

like image 560
Joshua Avatar asked Jan 20 '10 15:01

Joshua


3 Answers

We did our project with GraphicsMagick and Java, Q&A here obvious influence our decision. It's a long way but we eventually got it done. We tweaked both GraphicsMagick and im4java very hard to get the performance and reliability we want. Thought I should contribute back: http://kennethxu.blogspot.com/2013/04/integrate-java-and-graphicsmagick.html

like image 96
Kenneth Xu Avatar answered Nov 03 '22 10:11

Kenneth Xu


It's definitely possible. Take a look at IM4Java, a Java abstraction around the commandline interfaces of various ImageMagick like tools (including GM) that feels like a language binding. Very little documentation, but sufficiently simple. Obviously your images have to be accessible from the OS (e.g. not inside ResourceBundles).

like image 28
ian Avatar answered Nov 03 '22 11:11

ian


Currently the only reasonable way to achieve this is by using the command line from Java (runtime.exec). You should use im4java to do this as suggested above. im4java will enable you to build up your "gm command" string using java method calls, it also provides a number of other useful features.

The big advantage of using this technique over actual language bindings is simplicity and reliability. Reliability is important especially if your Java app is running on a Java based server or servlet engine like tomcat. The reason being that a memory fault or other error while using language bindings could bring down the whole Java virtual machine.

like image 1
toc777 Avatar answered Nov 03 '22 11:11

toc777