Search code examples
pythongraphicsimagemagickgraphicsmagickpgmagick

Flood fill with Graphicsmagick or pgmagick


Question

What is a good way to use flood fill with the Graphicsmagick command line or its pgmagick wrapper for python?

Background

So far this is what I have, but its saying that the signatures do not match:

Code:
from pgmagick import Image, ColorRGB

img = Image('C:\\test.png')
cRGB = ColorRGB(256.0, 256.0, 256.0)
geo = Geometry(1,1)
img.floodFillColor(geo, cRGB, cRGB)
Error:
  File "C:/Dropbox/COC/automate/coc_automate/python/__init__.py", line 62, in take_main_screen_shot
    img.floodFillColor(geo, cRGB, cRGB)
Boost.Python.ArgumentError: Python argument types in
    Image.floodFillColor(Image, Geometry, ColorRGB, ColorRGB)
did not match C++ signature:
    floodFillColor(class Magick::Image {lvalue}, class Magick::Geometry, class Magick::Color, class Magick::Color)
    floodFillColor(class Magick::Image {lvalue}, class Magick::Geometry, class Magick::Color)

Extra

Also, if you know of a better way that I can manipulate graphics from a Python application or the windows command line, I'm all ears. I'm starting to feel like I may be using the wrong tool for this with the state of the documentation.


Solution

  • I would recommend taking a look at the Python Imaging Library (PIL)

    e.g. draw a gray cross over an image

    import Image, ImageDraw
    
    im = Image.open("lena.pgm")
    
    draw = ImageDraw.Draw(im)
    draw.line((0, 0) + im.size, fill=128)
    draw.line((0, im.size[1], im.size[0], 0), fill=128)
    del draw 
    
    # write to stdout
    im.save(sys.stdout, "PNG")