【发布时间】:2017-07-20 00:12:01
【问题描述】:
如何在 wand (python) 中并排堆叠两个图像?复合方法是可用的,但它将一个图像放在另一个图像之上。 我想要类似 numpy.vstack 的东西。
【问题讨论】:
标签: python image-processing wand
如何在 wand (python) 中并排堆叠两个图像?复合方法是可用的,但它将一个图像放在另一个图像之上。 我想要类似 numpy.vstack 的东西。
【问题讨论】:
标签: python image-processing wand
您还可以使用smush() 与图像之间的可选间距,并且:
stacked=True 用于垂直(一个在另一个之上)堆叠,或stacked=False 用于并排堆叠。from wand.image import Image
im = Image(filename="rose:")
with im as output:
output.sequence.append(im)
output.sequence.append(im)
output.smush(True, 5)
output.save(filename='result.png')
如果您不希望图像之间有任何间距,请使用offset=0 或仅使用concat() 而不是smush(),但方式完全相同。
【讨论】:
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。
【讨论】: