ImageMagick无效参数

时间:2018-04-17 10:26:14

标签: java aem processbuilder imagemagick-convert

我正在使用process命令运行imagemagic,如下所示:

try {
            System.out.println(" Image is Processing :: " + assetDetails.getName() + "Original Size :: " + assetDetails.getSize());
            ProcessBuilder pb = new ProcessBuilder("convert", "-quality", "85%", assetDetails.getAssetNode().getPath(), assetDetails.getAssetNode().getPath());
            pb.redirectErrorStream(true);

            Process p = pb.start();
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            System.out.println(p.waitFor());
            session.save();

        } catch (final IOException | RepositoryException | InterruptedException ex) {
            ex.printStackTrace();
        }

我收到错误:Invalid Parameter - 85%并且图片没有压缩。但是,如果我从本地运行相同的命令。它成功执行。

C:\Users\vdhim6\Desktop\imgcompression>convert -quality 85% source.jpg destination.jpg

C:\Users\vdhim6\Desktop\imgcompression>

1 个答案:

答案 0 :(得分:0)

应提供convert.exe的完整路径,如下所示:

    ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\ImageMagick-6.9.9-Q16\\convert.exe", "-quality", "85%", assetDetails.getAssetNode().getPath(), assetDetails.getAssetNode().getPath());