【问题标题】:Wand: Image.composite turns bg-image black魔杖:Image.composite 将 bg-image 变为黑色
【发布时间】:2017-07-24 18:19:42
【问题描述】:

我有问题。以下代码确实有效,它结合了两个图像。但是最终合成中的背景图像是完全黑色的。

大家猜一猜,这里有什么问题?

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)

【问题讨论】:

  • new_image 的背景定义为“无”,因此最终图像应该有黑色背景。你在期待什么?

标签: python imagemagick wand magickwand


【解决方案1】:

尝试删除 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")

如果您尝试重用 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)

【讨论】:

  • 有效!伟大的!谢谢!
猜你喜欢
  • 2015-10-23
  • 2015-12-06
  • 1970-01-01
  • 2019-08-26
  • 1970-01-01
  • 2015-08-22
  • 1970-01-01
  • 2017-12-24
  • 2015-07-07
相关资源
最近更新 更多