/ /あらかじめ定義されたパターンで画像をワンドで塗りつぶす - python、imagemagick、composite、wand

Wand - python、imagemagick、composite、wandであらかじめ定義されたパターンで画像を塗りつぶす

私はイメージを持っています(そのようなもの: マスク2つの整数は、最終的な画像の幅と高さを表します。ワンドの文書によると 空の画像を開く

with Image(width=200, height=100) as img:
img.save(filename="200x100-transparent.png")

背景が透明な空の画像になります。 さて、問題は次のとおりです。同じ空の画像を作成する方法 マスク 背景パターンとしての画像?

composite CLIコマンド自体には、次の演算子があります。

-tile repeat composite operation across and down image

しかし、Wandでどのように同じことを達成するのでしょうか。

回答:

回答№1は2

さて、ImageMagickのコンポジットを見た後 ソースコード それ自体、ワンド主導のソリューションは次のようになるはずであることが明らかになりました。

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")

回答№2の場合は0

タイトルイテレータの作成は 最善の解決策 私の考えでは。しかしもう一つ ハッキー メソッドを呼び出すことになります 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")

ワンド付きの事前定義パターン