0

我正在尝试通过 IM4Java 库使用 Image Magick 调整图像大小。

它工作得很好,除了图像没有居中。我已经通过外部命令行运行了这些相同的命令,它们运行良好。

谁能告诉我为什么这不起作用?

private void convertImage(int width, int height, String source, String dest)
        throws IOException, IM4JavaException, InterruptedException
{
    // create command
    ConvertCmd cmd = new ConvertCmd();

    // create the operation, add images and operators/options
    IMOperation op = new IMOperation();
    op.addImage(source);

    op.thumbnail(width, height, ">");
    op.extent(width, height);
    op.gravity("center");
    op.background("white");

    op.addImage(dest);
    ProcessStarter.setGlobalSearchPath("/usr/local/bin");
    cmd.setOutputConsumer(imageMagickOutputter);
    cmd.run(op);

}

带背景的命令结果切换为蓝色

4

1 回答 1

1

操作的顺序很重要:将重力操作放在缩略图和范围之前:

        IMOperation op = new IMOperation();
        op.addImage(sourceFile);
        op.gravity("center");
        op.thumbnail(width, height, '^');
        op.extent(width,height);
        op.addImage(destinationFile);
于 2014-10-01T12:40:41.120 回答