wand
wand copied to clipboard
Drawing Rounded Rectangle does not work if pyplot used / or "unlucky dimensions" entered
I'm running Ubuntu 21.10, Python 3.9.7 and Wand 0.6.7. There is an issue if my python code first does some pyplot stuff and then drawing an rounded rectangle using wand.
The following code does not throw any error message, however the resulting file output.png is empty (NO green rectangle is drawn):
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# do some pyplot stuff
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
# Do some wand stuff
img = Image(width=850, height=600) # This dimension does NOT work
with Drawing() as drw:
drw.fill_color = Color('green')
drw.rectangle(left=0,
top=0,
width=img.width,
height=img.height,
radius=img.width*0.05)
drw(img)
img.save(filename='output.png')
Now the strange part. The code works fine if I remove seemingly unrelated pyplot stuff at the beginning:
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# Do some wand stuff
img = Image(width=850, height=600) # This dimension does NOT work
with Drawing() as drw:
drw.fill_color = Color('green')
drw.rectangle(left=0,
top=0,
width=img.width,
height=img.height,
radius=img.width*0.05)
drw(img)
img.save(filename='output.png')
Now the super crazy thing: I don't need to remove the pyplot stuff, because I can also make the code running by simply changing the dimensions:
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
# do some pyplot stuff
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
# Do some wand stuff
#img = Image(width=850, height=600) # This dimension does not work
img = Image(width=800, height=600) # This dimension does work
with Drawing() as drw:
drw.fill_color = Color('green')
drw.rectangle(left=0,
top=0,
width=img.width,
height=img.height,
radius=img.width*0.05)
drw(img)
img.save(filename='output.png')
Thanks for your help!
Although all 3 examples work for me on Ubuntu 21.10, try allocating pixels before drawing.
with Image(width=850, height=600, pseudo='xc:transparent') as img:
# ...