Reputation: 624
I have written a class that execute convert command of imagemagic.
public class ImageMagicDemo {
public static void main(String[] argp){
ProcessBuilder pb2 = new ProcessBuilder("G:\\project\\installation\\imagemagic\\convert","G:\\demo\\image\\frame.jpg", "-resize", "20x20",
"G:\\demo\\image\\resizeImage\\frame1.jpg");
pb2.redirectErrorStream(true);
Process p2;
try {
p2 = pb2.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p2.getInputStream()));
String line = null;
while((line=br.readLine())!=null){
System.out.println(line);
}
System.out.println("2"+p2.waitFor());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But I am getting the following response
convert.exe: unable to open image `G:\demo\image\frame.jpg': No such file or directory @ error/blob.c/OpenBlob/2692.
convert.exe: unable to load module `G:\project\installation\imagemagic\modules\coders\IM_MOD_RL_JPEG_.dll': The specified module could not be found.
@ error/module.c/OpenModule/1282.
convert.exe: no decode delegate for this image format `JPG' @ error/constitute.c/ReadImage/501.
convert.exe: no images defined `G:\demo\image\resizeImage\frame1.jpg' @ error/convert.c/ConvertImageCommand/3212.
Same problem is with .png file.I have installed ImageMagick-6.9.1-2-Q16-x64-dll.exe on Window8. However if I run the following command on command prompt
convert -resize 1024x768 G:\\demo\\image\\frame.jpg G:\\demo\\image\\resizeImage\\frame1.jpg
It successfully execute and copy the resized image in destination folder.If anyone knows please reply.
Thanks
Upvotes: 2
Views: 4444
Reputation: 43
In my case it allready helped to install the static Version of ImageMagick instead off the dynamic/dll. Give it a try. Btw. call-funktionality should be same with x86 or x64.
Upvotes: 0
Reputation: 347204
I can get it to work, only if I change the working directory from which the executed is to be run, using ProcessBuilder#directory(File)
ProcessBuilder pb = new ProcessBuilder(
"C:\\Program Files\\ImageMagick-6.9.1-Q16\\convert.exe",
"C:\\Path\to\Large.png",
"-resize", "1027x768",
"C:\\Path\to\small.png");
try {
pb.inheritIO();
pb.redirectErrorStream();
pb.directory(new File("C:\\Program Files\\ImageMagick-6.9.1-Q16"));
Process p = pb.start();
try (InputStream is = p.getInputStream()) {
int in = -1;
while ((in = is.read()) != -1) {
System.out.print((char)in);
}
}
System.out.println("Exited with " + p.waitFor());
} catch (IOException | InterruptedException ex) {
ex.printStackTrace();
}
Upvotes: 5