Im4java+imagemagick/graphicsmagick

Source: Internet
Author: User
Tags imagemagick

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.