在Mac上安装ImageMagick,通过im4java调用

你离开我真会死。 提交于 2019-11-27 06:41:22

在Mac上我是通过 Homebrew来进行ImageMagick的安装的

1、安装brew 

$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)”



2、安装ImageMagick 

$ brew install imagemagick



3、起初是想通过JMagick来实现的,但是考虑到调用Im4java的优势和在Mac下安装的繁琐,选择了Im4java。

Advantages of im4java: the interface of the IM commandline is quite stable, so your java program (and the im4java-library) will work across many versions of IM. im4java also provides a better OO interface (the "language" of the IM-commandline with it's postfix-operation notation translates very easily into OO-notation). And most important: you can use im4java everywhere JMagick can't be used because of the JNI hazard (e.g. java application servers).

4、实现

ProcessStarter.setGlobalSearchPath("/usr/local/bin/");
			IMOperation op = new IMOperation();
			op.addImage("/Users/liyinjun/Desktop/12.jpg");
			op.resize(100,200);
			op.addImage("/Users/liyinjun/Desktop/new_12.jpg");
			ConvertCmd convert = new ConvertCmd();
			try {
				convert.run(op);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IM4JavaException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}



下面是转换的图片



这里是im4java 使用向导 http://im4java.sourceforge.net/docs/dev-guide.html 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!