im4java和imagemagick-为什么重力参数不起作用?
我正试图通过IM4Java库使用image Magick调整图像大小 它工作得很好,只是图像没有居中。我已经通过外部命令行运行了这些相同的命令,它们工作得很好 有人能告诉我为什么这不起作用吗im4java和imagemagick-为什么重力参数不起作用?,java,imagemagick,im4java,Java,Imagemagick,Im4java,我正试图通过IM4Java库使用image Magick调整图像大小 它工作得很好,只是图像没有居中。我已经通过外部命令行运行了这些相同的命令,它们工作得很好 有人能告诉我为什么这不起作用吗 private void convertImage(int width, int height, String source, String dest) throws IOException, IM4JavaException, InterruptedException { // c
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);
}
操作顺序很重要:将重力操作放在缩略图和范围之前:
IMOperation op = new IMOperation();
op.addImage(sourceFile);
op.gravity("center");
op.thumbnail(width, height, '^');
op.extent(width,height);
op.addImage(destinationFile);