1. New and old version difference
The old version of ImageMagick, using the convert.exe.
The new version is using Magick.exe.
The difference is that when used, the command is different.
convert -quality 75% D:/1.jpg E:/1.jpgmagick -quality 75% D:/1.jpg E:/1.jpg
Without doing more testing, what I'm actually using now is:
The new version is now 7.0.7 http://www.imagemagick.org/script/download.php
The old version is 6.2.7 Https://pan.baidu.com/s/1gfpPo1X
2.Why???
Because the Windows system has the same command, convert. The estimate was based on the consideration that ImageMagick converted convert to magick.
3. Why use the old version
It is now not successful to call ImageMagick directly using Java in the form of a call to CMD. The reason was not found.
String command = "cmd /c magick -quality 75% E:/1.jpg E:/2.jpg"; Process p = null; Runtime run = Runtime.getRuntime(); try { p = run.exec(command); System.out.println(command); p.waitFor(); in = p.getInputStream(); BufferedReader read = new BufferedReader(new InputStreamReader(in)); String result = read.readLine(); System.out.println("INFO:"+result); } catch (Exception e) { e.printStackTrace(); }
Moreover, the previous Im4java used in Linux to call ImageMagick, Im4java,,, does not support the new version. Im4java older, should be in ImageMagick before the new version is not updated, so Im4java and the new version of ImageMagick incompatible.
So, choose to use the old version.
Use of 4.im4java
Introducing Dependencies
<dependency> <groupId>org.im4java</groupId> <artifactId>im4java</artifactId> <version>1.4.0</version></dependency>
Java Methods for compressing pictures
long zoomstart,zoomend;zoomstart = System.currentTimeMillis();start = System.currentTimeMillis();IMOperation operation = new IMOperation();operation.addImage(orgfileName);operation.quality(0.1);operation.addImage(zoomfileName);ConvertCmd cmd = new ConvertCmd();cmd.setSearchPath("C:\\Program Files (x86)\\ImageMagick-6.2.7-Q16"); //Windows需要设置,Linux不需要cmd.run(operation);zoomend = System.currentTimeMillis(); System.out.println("生成压缩图片时间 start time:" + zoomstart+ "; end time:" + zoomend+ "; Run Time:" + (zoomend - zoomstart) + "(ms)");
ImageMagick use on Windows