serisAK
serisAK

Reputation: 43

Replace a color using Wand

I'm trying to replace a color in an image with another color, by defining the coordinates of one of its pixels. But when I run the code the result is exactly the same as the original.

here's the original image:

here's the code:

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

with Drawing() as draw:
    draw.fill_color = Color('#ff0000')
    draw.color(192,84,'replace')

    with Image(filename='rgb.jpg') as img:
        img.save(filename='rgr.jpg')
        display(img)

192,84 is somewhere around the middle of the blue section of the image. Which should now be red, except nothing changes. I thought maybe it has something to do with the "fuzz" but i can't figure out the syntax. I tried:

draw.color(192,84,'replace',fuzz=10)

But I got the "unexpected keyword argument 'fuzz'" error.

so I tried:

draw.fuzz = 10

I got no errors, but the image still had no change.

Upvotes: 1

Views: 1216

Answers (1)

emcconville
emcconville

Reputation: 24419

I would guess that you did not apply the drawing context to the image.

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

with Drawing() as draw:
    draw.fill_color = Color('#ff0000')
    draw.color(192,84,'replace')

    with Image(filename='gb.jpg') as img:
        draw(img)  # <= here
        img.save(filename='rgr.jpg')
        display(omg)

Replace a color using Wand

Upvotes: 1

Related Questions