[英]Fill an image with pre-defined pattern with Wand
好了,在查看了ImageMagick的Composite 源代码本身之后,很明显,Wand驱动的解决方案应如下所示:
with Image(width=x, height=y) as img:
for x in xrange(0, img.width, crop_mask_path.width):
for y in xrange(0, img.height, crop_mask_path.height):
img.composite_channel('default_channels', crop_mask_path, 'over', x, y)
img.save(filename='patterned_image.png')
在我看来,构建标题迭代器是最好的解决方案 。 但是,另一种令人讨厌的方法是调用tile:
协议,并允许内部ImageMagick方法处理合成。 您将失去DIY继承的控件,但是在优化的IM系统上可以获得一些性能。
from wand.image import Image
from wand.api import library
with Image() as img:
# Same as `-size 400x400' needed by tile: protocol.
library.MagickSetOption(img.wand, 'size', '400x400')
# Prefix filename with `tile:' protocol.
img.read(filename='tile:rose.png')
img.save(filename='tile_rose.png')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.