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

Occasional image corruption with pseudo (and draw?) #617

Open
groucho86 opened this issue Mar 19, 2023 · 3 comments
Open

Occasional image corruption with pseudo (and draw?) #617

groucho86 opened this issue Mar 19, 2023 · 3 comments

Comments

@groucho86
Copy link

I'm sometimes getting "glitchy" imagery when my background uses "checkerboard" and I draw shapes. It happens about 40% of the time.

Code sample to (sometimes) reproduce the issue:

from wand.image import Image
from wand.color import Color
from wand.display import display
from wand.drawing import Drawing

for f in range(8):
    with Drawing() as fx_wand:
        
        with Image(width=640, height=360, background='white', pseudo='pattern:checkerboard') as img:
            img.metadata['colorspace:auto-grayscale'] = 'false' 
            img.metadata['PixelAspectRatio'] = str(1.0)
            img.colorspace='srgb'
            img.units = 'pixelsperinch'
            img.format='png'      
            img.resolution = 220       
            fx_wand.push_pattern('green_circle', 0, 0, 10, 10)
            fx_wand.fill_color = 'green'
            fx_wand.stroke_color = 'black'
            fx_wand.circle(origin=(5, 5), perimeter=(5, 0))
            fx_wand.pop_pattern()
            fx_wand.set_fill_pattern_url('#green_circle')
            fx_wand.rectangle(top=5, left=5, width=40, height=40)
            fx_wand.draw(img)
            display(img)

Out of the 8 rendered images, 3 exhibited glitches. Is this a bug or is there a proper method to avoid it?

glitchy

@emcconville
Copy link
Owner

That looks like a buffer that's not cleared -- not a Wand issue. Are you using X11 or Wayland (or XWayland)?

First thought would be to replace display(img) with img.save(filename='output_{0}.png'.format(f)), and see if the artifacts are not present when you see them on the screen. If so, this is a buffer issue in the desktop's window manager.
If the artifacts are present in the image saved to disk, then that'll be either a ImageMagick, or Python issue.

@groucho86
Copy link
Author

Thanks Eric. I’m testing the code in pydev (Eclispe) on an M1 MacBook Pro.

Saving the images result in the same inconsistent behavior.

@emcconville
Copy link
Owner

Sorry, can't offer much help with that environment. Here's a few more experiments that might help determine the cause.

Goals

  • Eliminate Wand's Drawing context, and use direct MVG input.
  • Repeat MVG input in a controlled CLI environment.

Part 1: Create MVG

Copy the following into a vector.mvg file in the same pydev environment.

push pattern green_circle 0 0 10 10
 fill '#000080800000'
 stroke '#000000000000'
 circle 5 5 5 0
pop pattern
fill url(#green_circle)
rectangle 5 5 45 45

Part 2: Execute in Python/Wand

Replace the original code above with the following.

from wand.image import Image
from wand.display import display

for _ in range(8):
    with Image(width=640, height=360, background="white", pseudo="pattern:checkerboard") as img:
        img.format = 'png'
        with Image(width=640, height=360, background="transparent", filename="MVG:vector.mvg") as draw:
            img.composite(draw)
            display(img)

Part 3: Repeat in CLI

Open a terminal, and cd to the same directory used by pydev. Run the following bash commands.

for i in $(seq 8)
do
  magick -size 640x360 -background white pattern:checkerboard \
    -background transparent MVG:vector.mvg -composite png:- | display png:-
done

Although, I think osx uses zsh now-a-days. You might need to replace for i in $(seq 8) with for (( i=0; i < 8; i++))

Hopefully this will help identify the cause.

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

No branches or pull requests

2 participants