im4javaで画像のサイズを取得する
http://kyle-in-jp.blogspot.jp/2009/02/im4java_19.html
この記事を参考に実装したら処理が非常に重かったので改良。
重い原因はverboseオプションを付けて詳細情報を出しているからだと思われる。
public static int[] getImageSize(File src) {
try {
IMOperation op = new IMOperation();
op.format("%wx%h");
op.addImage(src.getAbsolutePath() + "[0]");
IdentifyCmd identify = new IdentifyCmd();
identify.setSearchPath(getImageMagickPath());
ArrayListOutputConsumer output = new ArrayListOutputConsumer();
identify.setOutputConsumer(output);
identify.run(op);
ArrayList<String> lines = output.getOutput();
if (lines.size() > 0) {
String line = lines.get(0);
String sz[] = line.split("x");
return new int[] { Integer.parseInt(sz[0]), Integer.parseInt(sz[1]) };
}
} catch (Exception e) {
}
return null;
}