Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing Rounded Rectangle does not work if pyplot used / or "unlucky dimensions" entered #584

Open
reisenmachtfreude opened this issue Jul 23, 2022 · 1 comment

Comments

@reisenmachtfreude
Copy link

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!

@emcconville
Copy link
Owner

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:
   # ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants