Imagemagick 使用graphicsmagick获取图像大小
对于我的一个项目,我正在使用im4java库并通过它向graphicsmagick发送命令 要获取图像大小,请执行以下操作:Imagemagick 使用graphicsmagick获取图像大小,imagemagick,graphicsmagick,im4java,Imagemagick,Graphicsmagick,Im4java,对于我的一个项目,我正在使用im4java库并通过它向graphicsmagick发送命令 要获取图像大小,请执行以下操作: identify -format \"%w,%h,\" test.png 我可以得到合适的尺寸,直到下面的结果。这次stderr更改了结果: [wx=0.345750, wy=0.358550, rx=0.648500, ry=0.330880 gx=0.321210, gy=0.597870, bx=0.155890, by=0.066040 163,
identify -format \"%w,%h,\" test.png
我可以得到合适的尺寸,直到下面的结果。这次stderr更改了结果:
[wx=0.345750, wy=0.358550, rx=0.648500, ry=0.330880
gx=0.321210, gy=0.597870, bx=0.155890, by=0.066040
163, 70,
identify: Ignoring incorrect cHRM value when sRGB is also present ]
有没有办法只获取图像大小而忽略stderr结果
提前感谢尝试向命令中添加
-quiet
以抑制错误消息,如下所示:
identify -quiet -format \"%w,%h,\" test.png
请执行以下操作:
标识-格式\“宽度=%w,高度=%h,\”test.png
然后解析结果,专门查找width=N和height=N//对我来说,“ping”是获取维度的最快方法
String resultFormat = "%w" + " " + "%h";
ArrayListOutputConsumer outputConsumer = new ArrayListOutputConsumer();
IdentifyCmd identify = new IdentifyCmd();
identify.setOutputConsumer(outputConsumer);
IMOperation op = new IMOperation();
op.ping();
op.format(resultFormat);
op.addImage("abc.jpg");
//Object[] arguments = new String[]{filePath};
try {
identify.createScript("c:\\_work\\temp\\magick-dimension.sh.txt", op); // this will show you the actual im4java generated command
identify.run(op);
} catch (IOException | InterruptedException | IM4JavaException e) {
//throw new ImageAccessException(e.getMessage(), e);
e.printStackTrace();
}
ArrayList<String> output = outputConsumer.getOutput();
String[] dimensions = output.get(0).split(separator);
Dimension result = new Dimension(Integer.valueOf(dimensions[0]), Integer.valueOf(dimensions[1]));
return result;
String resultFormat=“%w”+“”+%h”;
ArrayListOutputConsumer outputConsumer=新的ArrayListOutputConsumer();
IdentifyCmd identify=新IdentifyCmd();
标识.setOutputConsumer(outputConsumer);
i操作op=新i操作();
op.ping();
op.format(结果格式);
op.addImage(“abc.jpg”);
//对象[]参数=新字符串[]{filePath};
试一试{
identify.createScript(“c:\\\\u work\\temp\\magick dimension.sh.txt”,op);//这将显示实际生成的im4java命令
识别、运行(op);
}捕获(IOException | InterruptedException | IM4JavaException e){
//抛出新的ImageAccessException(e.getMessage(),e);
e、 printStackTrace();
}
ArrayList output=outputConsumer.getOutput();
String[]dimensions=output.get(0).split(分隔符);
维度结果=新维度(Integer.valueOf(维度[0]),Integer.valueOf(维度[1]);
返回结果;