The Im4java jar package can be found in the MAVEN library.
<dependency> <groupId>org.im4java</groupId> <artifactid>im4java</artifactid > <version>1.4.0</version> </dependency>
Once the ImageMagick or GraphicsMagick are installed, the environment variables will be well-equipped.
Sample code:
Import Org.im4java.core.convertcmd;import Org.im4java.core.imoperation;public class Test {public static void main ( String[] args) {try {zoomimage (1000,800, "f:/u02/origin/20141215/loginbigbg.jpg", "f:/u02/origin/20141215/ Loginbigbg_new.jpg ");} catch (Exception e) {e.printstacktrace ();}} public static void Zoomimage (integer width, integer height, string srcpath, String NewPath) throws Exception { Imoperation op = new Imoperation (); Op.addimage (Srcpath); if (width = = null) {//scales the picture according to height op.resize (null, height); }else if (height = = null) {//scales the picture by width op.resize (width, null); }else {op.resize (width, height); } op.addimage (NewPath); Here no parameter or parameter is False is using Imagemagick,true is using GraphicsMagick convertcmd convert = new Convertcmd ();//Convert.sets Earchpath ("G:/tool/graphicsmagick-1.3.20-q16"); Convert.setsearchpath ("G:/tool/imagemagick-6.9.0-q16"); Convert.run (OP); }}
Where Setsearchpath is required to be set in the Windows environment.
Convertcmd convert = new Convertcmd ();
This sentence, if only ImageMagick is installed, but the definition is written as new Convertcmd (true), will be reported to find "GM" error.
Org.im4java.core.CommandException:java.io.FileNotFoundException:gmat Org.im4java.core.ImageCommand.run ( imagecommand.java:219) at Com.trs.rk.test.Test.zoomImage (test.java:31) at Com.trs.rk.test.Test.main (test.java:10)
Similarly, if only GraphicsMagick is installed, but new Convertcmd (false) or no parameter, the error of convert cannot be found.
Org.im4java.core.CommandException:java.io.FileNotFoundException:convertat Org.im4java.core.ImageCommand.run ( imagecommand.java:219) at Com.trs.rk.test.Test.zoomImage (test.java:31) at Com.trs.rk.test.Test.main (test.java:10)
Transferred from: MZGLZZC's Column
Im4java+imagemagick/graphicsmagick