魔杖:Image.composite将bg-image变为黑色

时间:2017-07-24 18:19:43

标签: python imagemagick wand magickwand

我有问题。以下代码确实有效,它将两个图像组合在一起。但最终作曲中的背景图像完全是黑色的。

任何猜测,这里的问题是什么?

from wand.image import Image

with Image(filename=bgimage) as back:
    with Image(filename=qrcode) as front:
        with Image(width=back.width, height=back.height) as new_image:
            new_image.composite(front, left=1000, top=900)
            new_image.save(filename=qr_output)

1 个答案:

答案 0 :(得分:0)

尝试删除new_image部分,并简化所有内容。

with Image(filename="wizard:") as back:
  with Image(filename="rose:") as front:
    back.composite(front,
                   top=back.height-front.height,
                   left=back.width-front.width)
    back.save(filename="/tmp/output.png")

output.png

如果您尝试重复使用back个实例,请使用wand.image.Image.clone

with Image(filename=bgimage) as back:
  with Image(filename=qrcode) as front:
     with back.clone() as new_image:
       new_image.composite(front, left=1000, top=900)
       new_image.save(filename=qr_output)