views:

19

answers:

2

i have a new problem in image magick that look strange .. i'm using mac osx snow leopard and i've installed image magick on it and it's working fine on command .. but when i call it from the grails class like the following snippet it gives me "Cannot run program "convert": error=2, No such file or directory"

the code is :-

 public static boolean resizeImage(String srcPath, String destPath,String size) {

    ArrayList<String> command = new ArrayList<String>(10);


    command.add("convert");
    command.add("-geometry");
    command.add(size);
    command.add("-quality");
    command.add("100" );
    command.add(srcPath);
    command.add(destPath);

    System.out.println(command);

    return exec((String[])command.toArray(new String[1]));
}

private static boolean exec(String[] command) {
    Process proc;

    try {
        //System.out.println("Trying to execute command " + Arrays.asList(command));
        proc = Runtime.getRuntime().exec(command);
    } catch (IOException e) {
        System.out.println("IOException while trying to execute " );
        for(int i =0 ; i<command.length; i++) {
        System.out.println(command[i]);
        }
        return false;
    }

    //System.out.println("Got process object, waiting to return.");

    int exitStatus;

    while (true) {
        try {
            exitStatus = proc.waitFor();
            break;
        } catch (java.lang.InterruptedException e) {
            System.out.println("Interrupted: Ignoring and waiting");
        }
    }
    if (exitStatus != 0) {
        System.out.println("Error executing command: " + exitStatus);
    }
    return (exitStatus == 0);
}

i've tried normal command like ls and it's ok so the problem is that grails can't find convert command itself.. is it a os problem or something?

A: 

You need to work out what your PATH is set to when you run a command from Java. It must be different to the one you have when running from the terminal.

Are you running Grails (via Tomcat?) as a different user? It might have a different path to your normal user.

leebutts
I'm using netbeans so it's using jetty i suppose.. so what can i do
Mohamed Emad Hegab
A: 

you might want to try one of the Image Plugins that are part of the grails ecosystem

http://www.grails.org/ImageTools+plugin

the grails path when the app is running in the server is probably different from running java from the command line

Aaron Saunders
i've tried it and that's why i need image magick.. the quality isn't so good and the options isn't like image magick
Mohamed Emad Hegab
i found the same problem so I just utilize the underlying jai libraries and created my own service
Aaron Saunders
this might resolve some of your problems http://sourceforge.net/projects/jmagick/
Aaron Saunders
jmagick is a very strange wrapper.. and i just couldn't find a tutorial that can help me installing it correctly in grails project on my mac
Mohamed Emad Hegab