我想用 Wand(Python 的 ImageMagick 绑定)将图像绘制到另一个图像中。源图像应完全替换目标图像(在给定位置)。
我可以用:
destinationImage.composite_channel(channel='all_channels', image=sourceImage, operator='replace', left=leftPosition, top=topPosition)
但我想知道是否有一个简单或更快的解决方案。
我想用 Wand(Python 的 ImageMagick 绑定)将图像绘制到另一个图像中。源图像应完全替换目标图像(在给定位置)。
我可以用:
destinationImage.composite_channel(channel='all_channels', image=sourceImage, operator='replace', left=leftPosition, top=topPosition)
但我想知道是否有一个简单或更快的解决方案。
但我想知道是否有一个简单或更快的解决方案。
并不真地。在wand的范围内,这将是最快的方法之一。为简单起见,您已经在一行代码上完成了所有工作。也许您可以使用Image.composite减少这种情况。
destinationImage.composite(sourceImage, leftPosition, topPosition)
但是您现在损害了当前解决方案的可读性。从长远来看,拥有带有channel='all_channels'
& kwargs的完整命令将对您有所帮助。operator='replace'
考虑在一年内重新审视代码。
destinationImage.composite(sourceImage, leftPosition, topPosition)
# versus
destinationImage.composite_channel(channel='all_channels',
image=sourceImage,
operator='replace',
left=leftPosition,
top=topPosition)
马上,无需访问 API 文档,您就知道第二个选项是用跨所有通道的源图像替换目标。这些事实在第一个变体中被隐藏或假设。