import java.util.*;
import org.im4java.core.*;
import org.im4java.process.*;
// im4java-0.96.0-bin.tar.bz2を解凍してim4java-0.96.0.jarはclasspathに通す
public class Im4java2
{
public static void main(String args[])
throws Exception
{
try
{
IMOperation op = new IMOperation();
op.verbose();
op.addImage("sf.jpg");
IdentifyCmd identify = new IdentifyCmd();
ArrayListOutputConsumer output = new ArrayListOutputConsumer();
identify.setOutputConsumer(output);
identify.run(op);
ArrayList lines = output.getOutput();
for(String line:lines){
if( line.startsWith(" Geometry: ") ){
if( line.indexOf("+") != -1 ){
String sz[] = line.substring(
" Geometry: ".length(),
line.indexOf("+")
).split("x");
System.out.println("width:" + sz[0]);
System.out.println("height:" + sz[1]);
}
}
}
}
catch(CommandException cex)
{
System.out.println(cex.getErrorText());
cex.printStackTrace();
}
}
}
関連情報
im4javaのまとめ
No comments:
Post a Comment