我使用 Image4j 和 graphicsmagick 来剪切图像,但是当我在 linux 中部署我的应用程序时崩溃了。
这是一个例外:
2015-04-14/15:26:46.712/CST [http-nio-8089-exec-47] 错误 org.im4java.core.CommandException: org.im4java.core.CommandException: gm convert: 无法恢复当前工作目录[没有权限]。2015-04-14/15:28:45.415/CST [http-nio-8089-exec-61] 错误 org.im4java.core.CommandException: org.im4java.core.CommandException: gm convert: 无法恢复当前工作目录[没有权限]。2015-04-14/15:30:10.699/CST [http-nio-8089-exec-68] 错误 org.im4java.core.CommandException: org.im4java.core.CommandException: gm convert: 无法恢复当前工作目录[没有权限]。2015-04-14/16:38:40.272/CST [http-nio-8089-exec-25] 错误 org.im4java.core.CommandException:java.io.IOException:无法运行程序“gm”:错误 = 23,系统 2015-04-14/16:40:35 中打开的文件太多。
这是我的代码:
private String cutImage(String filename ,String srcPath, String newPath, String urlPath , int sourceWidth, int sourceHeight, int cutNum) throws Exception {
StringBuilder sb = new StringBuilder();
int everyHeight = sourceHeight/cutNum;
ConvertCmd convert = new ConvertCmd(Boolean.TRUE);
for(int i = 0 ; i < cutNum ; i++) {
GMOperation op = new GMOperation();
op.addImage(srcPath+filename);
int startX = 0;
int startY = everyHeight * i;
int width = sourceWidth;
int height = everyHeight;
op.crop(width, height, startX, startY);
op.addImage(newPath+i+"_"+filename);
convert.run(op);
if( i == 0) {
sb.append(urlPath+i+"_"+filename);
} else {
sb.append(";"+urlPath+i+"_"+filename);
}
}
return sb.toString();
}