先安装GraphicsMagick
/**
*
* @param srcImgPath 源文件图片地址
* @param src2ImagePath 需要拼接到srcImgPath图片上的地址
* @param targetImgPath 拼接后的图片地址
* @throws IOException
* @throws InterruptedException
* @throws IM4JavaException
*/
public static void test(String srcImgPath,String src2ImagePath,String targetImgPath) throws IOException, InterruptedException, IM4JavaException{
IMOperation op = new IMOperation();
op.addImage(srcImgPath);
op.draw("image Over " + 100 + "," + 100+ " " + 150 + ","
+ 150 + " " + src2ImagePath);//op.draw("image Over x,y x1,y1 XX.img.jpg"); x,y 是图片左上角的坐标,x1,y1则是这个图片拼接到原图的大小
op.addImage(targetImgPath);
// IM4JAVA是同时支持ImageMagick和GraphicsMagick的,如果为true则使用GM,如果为false支持IM。
ConvertCmd cmd = new ConvertCmd(true);
String osName = System.getProperty("os.name").toLowerCase();
if (osName.indexOf("win") >= 0) { // linux下不要设置此值,不然会报错
cmd.setSearchPath("C://Program Files//GraphicsMagick-1.3.18-Q8");
}
cmd.setErrorConsumer(StandardStream.STDERR);
cmd.run(op);
}
参考文档:
http://www.imagemagick.org/script/convert.php
http://www.open-open.com/lib/view/open1355754261963.html