2
votes

I'm trying to have ImageMagick run from grails to convert some images when I run the command to make an image nothing happens. I get no errors, no information returned nothing at all. I've tried running other commands like touch and ps ux just to see if they work and they all work fine. It just seems like the imagemagick commands are getting lost and I''m not sure what to do. Here is the code I've been working with.

String command = CH.config.ImageMagickPath + "/convert -size 40x20 xc:red  xc:blue -append -rotate 90 append_rotate.gif"
println command
command.execute()

CH.config.ImageMagickPath is set up to where imagemagick/bin is. I've taken what is shown in
println command
and run it in a terminal and it works fine. Is there any reason why I can't get IM to work from grails?


Okay I used just java to code it and now i get this error:

dyld: Library not loaded: /ImageMagick-6.6.1/lib/libMagickCore.3.dylib Referenced from: /Library/ImageMagick/bin/convert Reason: image not found

2
Is there a space missing before /convert?ataylor

2 Answers

1
votes

I've just done something quite similar:

def convert = ["/usr/bin/convert","/opt/local/bin/convert"].find( { new File(it as String).exists() })
File thumbnail = new File(f.getParentFile(),FilenameUtils.getBaseName(f.getName()) + ".thumbnail.png")
ProcessBuilder pb = new ProcessBuilder()
        .command(convert, f.getName(), "-thumbnail", "128x128>","-bordercolor","snow","-background","black", "-polaroid", "0", thumbnail.getName())
        .directory(f.getParentFile());

int result = pb.start().waitFor()

if( result != 0 ){
  throw new ImageMagickException("thumbnail generation failured, return code:" + result);
}

It's a little bit more verbose (java is way to ingrained in my mind) but it does work.

Note that String.execute returns a process object, you need to call waitFor() in before checking for any generated files or what not. Also make sure you check the return code from this to see as this will give you a hint as to what has gone wrong.

0
votes

I would suggest using JMagick which is a JNI wrapper around the imagemagick library. It will also be more efficient than invoking execute().