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.