Reputation: 50362
What is a good way to use flood fill with the Graphicsmagick command line or its pgmagick wrapper for python?
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)
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.
Upvotes: 4
Views: 1061
Reputation: 2237
As you say, the documentation isn't great. pgmagick is a thin Python wrapper for a C++ frontend, so you have to dig through the layers of interface to figure out how to make it work. Unless you need the extra features, Pillow is probably a better choice.
I've been using pgmagick with ImageMagick, rather than GraphicsMagick, as the backend. I don't know whether that makes much difference. In any case, here are the tweaks I needed to make to get your code to work:
use Color rather than RGBColor
from pgmagick import Color
color = Color('white')
provide two more 0s when instantiating the Geometry object:
from pgmagick import Geometry
geo = Geometry(0, 0, 1, 1)
rather than passing two Color arguments to floodFillColor, call fillColor first and then call floodFillColor, like this:
img.fillColor(color)
img.floodFillColor(geo, color)
Upvotes: 1
Reputation: 9816
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")
Upvotes: 1