在 imagemagick 中将一个图像绘制到另一个图像中?

Draw an image into another one in imagemagick?

我想用 Wand(Python 的 ImageMagick 绑定)将一个图像绘制到另一个图像中。源图像应完全替换目标图像(在给定位置)。

我可以使用:

destinationImage.composite_channel(channel='all_channels', image=sourceImage, operator='replace', left=leftPosition, top=topPosition)

但我想知道是否有更简单或更快的解决方案。

But I was wondering if there is a simple or faster solution.

不是真的。在, this would be one of the fastest methods. For simplicity, your already doing everything on one line of code. Perhaps you can reduce this with Image.composite.

范围内
destinationImage.composite(sourceImage, leftPosition, topPosition)

但是您现在损害了当前解决方案的可读性。拥有 channel='all_channels'operator='replace' kwargs 的完整命令将在长期 运行 中帮助你。想想一年后重温代码。

destinationImage.composite(sourceImage, leftPosition, topPosition)
# versus
destinationImage.composite_channel(channel='all_channels',
                                   image=sourceImage,
                                   operator='replace',
                                   left=leftPosition,
                                   top=topPosition)

马上,无需点击 API 文档,您就知道第二个选项是在所有渠道中将目标替换为源图像。这些事实在第一个变体中被隐藏或假定。