I am using ImageMagick's convert tool to convert images from within my Java program running on Mac OS X. I am using the following code, which I adapted from here.
public static void convertToJPG(String originalFile, String newFile) throws Exception {
executeCommand("/usr/local/ImageMagick-6.6.7/bin/convert", originalFile, newFile);
}
private static void executeCommand(String... command) throws Exception {
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
Process p = pb.start();
int exitStatus = p.waitFor();
System.out.println(exitStatus);
if(exitStatus != 0)
throw new Exception("Error converting image.");
}
However, when I do this, I get an exit status of 133 and the error message below. I am assuming that this has something to do with permissions, as when I run the same command from the terminal, it works fine.
Error message:
dyld: Library not loaded: /ImageMagick-6.6.7/lib/libMagickCore.4.dylib
Referenced from: /usr/local/ImageMagick-6.6.7/bin/convert
Reason: image not found
Edit: Ok, so it turns out that I was getting the above error message due to Java not being able to see the DYLD_LIBRARY_PATH
environment variable. So I restarted Eclipse and everything worked.
Return code 133 = 128 + 5 = <terminated by signal> + SIGTRAP
See http://tldp.org/LDP/abs/html/exitcodes.html and the output of "kill -l".
While I wasn't able to find anything about a 133 return code, I did notice that you aren't reading the command standard out / standard error stream. I'd suggest reading that to see if ImageMagick is giving you some more helpful output. There's a question here that deals with more complex use cases of the Runtime.exec() method, but the best basic way to do it is with this method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With