Reputation: 440
I am using imagemagick in my application. Our development machine is Windows and live server is linux. Now, in online it is working fine online. But not in development machine. I downloaded and installed Imagemagick latest release for Windows and when i try the below command in DOS-prompt, it is working fine.
convert -sample 100x100 D:\test.jpg D:\test-cropped.jpg
But when i run the same as command-line in Java program, it is not working and not giving any error too. My code is :
Runtime.getRuntime().exec("convert -sample 250x150 "+pathName+digest+".jpg "+pathName+digest+"_thumb.jpg");
Any help is appareciated.
Upvotes: 1
Views: 1649
Reputation: 1
In my case, the problem I was facing that from java compare
command was working fine using Runtime.getRuntime().exec(), but when using convert
, it was not working and returning me exit value as 4.
Compare
execution returns exit value 0, telling that it is successfully executed.
I have system path
updated with the ImageMagic's installation directory, still it was not picking 'convert' exe file. So, I started giving complete path of the convert.exe file instead of only writing only convert
e.g:
Runtime.getRuntime().exec("C:/Program files/ImageMagic......../convert.exe myImage1 -draw .... myImage2")
and it worked fine this time.
Some how system was not able to pick the convert
application and giving full path sorted it out. May be this solution would help someone facing same type of issue.
Upvotes: 0
Reputation: 718698
I suspect the problem is spaces in pathnames, but the solution is NOT to use escapes or quotes. The exec(String)
method splits the string into "arguments" in a completely naive fashion by looking for white-space. It pays no attention whatsoever to quoting, etcetera. Instead, you will end up with command names and arguments that have quote characters, etcetera embedded in them.
The solution is to use the overload of exec
that takes a String[]
, and do the argument splitting yourself; e.g.
Runtime.getRuntime().exec(new String[]{
"convert", // or "D:\\Program Files (x86)\\ImageMagick-6.8.0-Q16\\convert\\"
"-sample",
"250x150",
pathName + digest + ".jpg",
pathName + digest + "_thumb.jpg"
});
The other thing you could do is to capture and print any output that is written to the processes stdout and stderr.
Upvotes: 0
Reputation: 16158
convert.exe
is available in ImageMagick installation directory. So you need to add ImageMagick installation directory in environment variable path
.
Another option is to provide complete path of convert.exe
as :
Runtime.getRuntime().exec("C:\\program files\\ImageMagick\\convert -sample 250x150 "+pathName+digest+".jpg "+pathName+digest+"_thumb.jpg");
Upvotes: 1
Reputation: 16440
try
convert
using the absolute pathinput file
and output file
, in case they contain space
Upvotes: 0