views:

165

answers:

2

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

A: 

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

armandino
+1  A: 

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.

Gareth Davis
So I've tried using the Java way also, and tried making a script that would run ImageMagick and then just return text. Grails executes the script fine and gets the text back from the script but imagemagick still isn't producing anything, although it seems like it's being called it's just not doing anything. As a test i took my script and ran it and a straight groovy console script and it worked. Run that from grails and NOTHING! I'm totally lost now.
TripWired
that sort of stuff can be very frustrating. only a couple of things spring to mind. First check the path of the file you are passing, the current directory is almost certainly not where you think it is, second run the command in the `grails console` command, this has the grails env, just in case that is really breaking something for your (it probably isn't). Give IM a really really big picture and then see if you can see the process in task manager, just to check that it's running, could us procexp to check the files it has open
Gareth Davis
So I just discovered I'm getting code 133 using the code that you shared above any ideas what that means?
TripWired
Only reference I can find in the ImageMagick src is FT_ERRORDEF_(Divide_By_Zero,0x85,"division by zero" ) - 0x85 is hex 133 Can only assume this is what you are getting. Not sure that's all that useful
Gareth Davis