【问题标题】:get image size with graphicsmagick使用 graphicsmagick 获取图像大小
【发布时间】:2015-01-05 11:27:23
【问题描述】:

对于我的一个项目,我正在使用 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, 70, 
identify: Ignoring incorrect cHRM value when sRGB is also present ]

有什么方法可以只获取图像大小而忽略 stderr 结果?

提前致谢

【问题讨论】:

    标签: imagemagick graphicsmagick im4java


    【解决方案1】:

    尝试将-quiet 添加到您的命令中以抑制错误消息,如下所示:

    identify -quiet -format \"%w,%h,\"  test.png
    

    【讨论】:

      【解决方案2】:

      执行以下操作:

      identify -format \"width=%w,height=%h,\" test.png

      然后解析结果专门寻找width=N和height=N

      【讨论】:

        【解决方案3】:

        // 对我来说,“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;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-01-30
          • 1970-01-01
          • 2011-07-11
          • 1970-01-01
          • 1970-01-01
          • 2014-08-11
          • 1970-01-01
          相关资源
          最近更新 更多