I use Image4j and graphicsmagick to cut image,but crashed wen i deploye my app in linux.
This is the exception:
2015-04-14/15:26:46.712/CST [http-nio-8089-exec-47] ERROR org.im4java.core.CommandException: org.im4java.core.CommandException: gm convert: Unable to restore current working directory [Permission denied]. 2015-04-14/15:28:45.415/CST [http-nio-8089-exec-61] ERROR org.im4java.core.CommandException: org.im4java.core.CommandException: gm convert: Unable to restore current working directory [Permission denied]. 2015-04-14/15:30:10.699/CST [http-nio-8089-exec-68] ERROR org.im4java.core.CommandException: org.im4java.core.CommandException: gm convert: Unable to restore current working directory [Permission denied]. 2015-04-14/16:38:40.272/CST [http-nio-8089-exec-25] ERROR org.im4java.core.CommandException: java.io.IOException: Cannot run program "gm": error=23, Too many open files in system 2015-04-14/16:40:35.196/CST [http-nio-8089-exec-34] ERROR org.im4java.core.CommandException: java.io.IOException: Cannot run program "gm": error=23, Too many open files in system
This is my code:
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();
}