[英]Stack two images side by side using Wand
如何以魔杖(python)並排堆疊兩個圖像? 復合方法是可用的,但是它將一個圖像放在另一個圖像之上。 我想要像numpy.vstack這樣的東西。
wand.image.Image.composite
方法接受top
和left
參數。 並排合成圖像沒有太多的努力...
with Image(filename="rose:") as left:
with Image(filename="rose:") as right:
with Image(width=left.width+right.width,
height=max(left.height, right.height)) as output:
output.composite(image=left, left=0, top=0)
output.composite(image=right, left=left.width, top=0)
output.save(filename="hstack.png")
...或堆積...
with Image(filename="rose:") as top:
with Image(filename="rose:") as bottom:
with Image(width=max(top.width, bottom.width),
height=top.height + bottom.height) as output:
output.composite(image=top, left=0, top=0)
output.composite(image=bottom, left=0, top=top.height)
output.save(filename="vstack.png")
當然,您也許可以簡化上面的示例,或者使用wand.api.library
實現MagickAppendImage
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.