以下代码会产生错误。
#!/usr/bin/env python
import collections.abc
from wand.image import Image, COMPOSITE_OPERATORS, DISTORTION_METHODS, CHANNELS
from wand.drawing import Drawing
wand_imageText = Image(width=1080,
height=1080,
background='rgb(0,0,0,0)')
with Drawing() as draw:
draw.font = 'Impact'
draw.font_size = 100
draw.gravity = 'north_west'
draw.fill_color = 'rgb(255, 255, 255, 255)'
draw.text(0, 0, "Let's rock!")
draw(wand_imageText)
wand_imageText.trim(color='rgb(0,0,0,0)',fuzz=0)
wand_imageText.save(filename='C:\\Temp\\Wand_trim_test.jpg')
wand_imageText.close()
文件“ C:\ Program Files \ Python37 \ lib \ site-packages \ wand \ image.py”,行865,已包装 结果=函数(自我,* args,** kwargs)文件“ C:\ Program Files \ Python37 \ lib \ site-packages \ wand \ image.py”,行4444,修剪 颜色或颜色为self [0,0]作为颜色:AttributeError:输入
是否可以使用魔杖修剪透明度?
答案 0 :(得分:1)
我发现我做错了。
trim函数的color参数必须是wand.color.Color对象,该函数才能起作用。
下面的代码使用fmw42的建议使用rgba(),并使用alpha值进行修整。
from wand.color import Color
wand_imageText.trim(color=Color('rgba(0,0,0,0)'),fuzz=0)