10
Oct
08

Installing JMagick on Mac OS X

This has got to be one of the most frustrating experiences of my life. I am working on a project that requires the use of ImageMagick and I am implementing the business layer of the application in Java. JMagick is a thin JNI wrapper for ImageMagick that whilst a little limited, will perform a good bulk of what can be achieved by using system calls to the ImageMagick commands. I had been using system calls with  Runtime.getRuntime().exec() which isn’t ideal (but for some of the more complex ImageMagick work like fine tuning compositions is still required). I first of all decided to go down the easy road (or what I thought was easy) and install all the pre-built libraries and binaries and hopefully it would all just work. I was wrong.

So without boring you and rambling on about how not to do it, I am going to tell you how I did it, from scratch after removing all trace of JMagick and ImageMagick from my machine.

First of all, IGNORE those pre-compiled binaries for OS X, COMPILE FROM SOURCE!

you can get it from 

ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz.

Just do a regular config, make and make install (Don’t worry about the warnings, you will get a good few of them most likely). If you try and run configure and you get some kind of error about the compiler not being able to make executables - then you will need to install the developer tools for OS X (just download XCode and install it).

Once you have compiled and installed ImageMagick (for those of you who want to cut and paste ./configure ; make ; make install) Then its time to build JMagick. Eric O’Laughlen has kindly created an OS X Leopard port for us of JMagick which you can get here.

I tried the binaries, couldn’t get them to work properly so again I COMPILED FROM SOURCE, download the source version and skip the binaries. 

To configure the build of JMagick Eric has added the very handy configure flag of ‘–with-shared-lib-ext’ this will allow you to have the build process automatically name the shared libraries that are generated with the correct OS X appropriate extension of .dylib.

Unpack Eric’s ported source code and run configure with the extension flag (./configure -with-shared-lib-ext=.dylib) and watch it go!

(When I was trying to build this using the binary install of ImageMagick for OS X I got from the ImageMagick site, I kept getting untold ‘header files not found‘ errors, of which was a nightmare because they were all clearly where they were supposed to be, no matter what I tried, I could not get it to build!).

Once the configuration is complete run ‘make’ and then ‘make install’, you should find that various libraries are installed in ‘/usr/local/lib/’. 

The important parts that you will need are sitting in the ‘lib/’ directory of your JMagick source, there should be three files (well two files and one symlink) jmagic-6.2.6.jar, libJMagick-6.2.6.dylib and libJMagick.dylib (symlink).

You can either add the jmagick-6.2.6.jar to your CLASSPATH or buildpath (if you are using Ant or Eclipse or something) or you can add it to

/Library/Java/Extensions

So it should be picked up automatically. You should then stick both the .dylib files in

/System/Library/Java/Extensions

(you should see a few other .dylib files in there as well)

This should be all you need to get it up and running, try this snippet - if it compiles and runs with no strange errors - you are in the money.

package test;

import magick.ImageInfo;
import magick.MagickImage;

public class Magic {
public static void main(String[] args) {

try {

ImageInfo info = new ImageInfo();
MagickImage image = new MagickImage(info);

} catch (Exception exp) {
exp.printStackTrace();

}

}

 

 

 

}

(You may need to add System.loadLibrary(“JMagick”); before you call initialize JMagick properly.)


3 Responses to “Installing JMagick on Mac OS X”


  1. 1 meena_r Oct 28th, 2008 at 2:57 pm

    Thanks for this post, I am very new to Image processing, and I tried installing imagemagick and jmagick libraries for image scaling purpose. Everything worked fine except the las step, when I tried running sample code it doesn’t finish, no exception, then I tried another thind

    ImageInfo info = new ImageInfo(”/Users/Meena/test.jpg”);
    MagickImage image = new MagickImage(info);
    image.setFileName(”test.jpg”);

    third line is throwing an exception saying “No image to set File name”.

    I would really appreciate if you could help me identify this issue, i am wondering could it be related to the environment setup?

    Thanks for reading my comment.

  2. 2 Krista Oct 28th, 2008 at 9:34 pm

    You write very well.

  3. 3 Mats Nov 6th, 2008 at 5:26 am

    Hi,

    I get the same problem as meena_r; the sample code above just hangs at the line MagickImage image = new MagickImage(info);

    If I change the code to rename or scale an image I get the exception “No image to scale/set Filename” etc.

    I was running this on os x 10.5.5

    Any help is much appriciated.

    -Mats


October 2008
M T W T F S S
« Aug   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031