Page 1 of 1

Passing list to PythonMagick.Image.draw()

Posted: 2012-02-20T02:26:39-07:00
by danielHeen
Hello!

I have successfully built and done some simple tests with PythonMagick-0.9.7, like reading and wrinting images.
BUT...
When I try to do a bit more complex stuff I run into problems. I want to draw a simple rectangle with transparent fill. Correct me if I'm wrong, but to do this I need to send multiple arguments to the draw command in a list. The problem is that PythonMagick doesn't except anything else then a C++ std::list of arguments. I've tried sending a python list with no result. Is this a limitation in the wrapper or am I missing a list function/class somewhere?

Is there any way of sending this kind of list from python?

here's what I'm trying to do:

Code: Select all

import PythonMagick as pm

im = pm.Image('1920x1080', 'gray70')

stroke = pm.DrawableStrokeColor(pm.Color(0,0,0,0))
fill = pm.DrawableFillColor(pm.Color(0,0,0,65535))
rectangle = pm.DrawableRectangle(20,20,1900,1060)
args = [stroke, fill, rectangle]

im.draw(args)
im.magick('PPM')

im.display()
I've also tried:

Code: Select all

im.draw(*args)
..and..

Code: Select all

im.draw(stroke)
im.draw(fill)
im.draw(rectangle)
Thanks for you time,
-Daniel

Re: Passing list to PythonMagick.Image.draw()

Posted: 2012-02-20T03:22:07-07:00
by danielHeen
With a red face I found out the problem..

I reread the Magick++ tutorial and noticed that I should set the fill, stroke and such in the Image instance..
This works:

Code: Select all

import PythonMagick as pm

im = pm.Image('1920x1080', 'gray70')

im.strokeColor(pm.Color(1600,0,0,0))
im.fillColor(pm.Color(0,0,0,65535))
rectangle = pm.DrawableRectangle(20,20,1900,1060)

im.draw(rectangle)
im.magick('PPM')

im.display()
-Daniel

Re: Passing list to PythonMagick.Image.draw()

Posted: 2012-02-20T04:50:01-07:00
by danielHeen
Please excuse my monolog here, but red face or not I ran into another problem..
At some point one would have to pass a list of arguments like the example below from http://www.imagemagick.org/Magick++/tut ... torial.pdf

Code: Select all

DrawableText::DrawableText(double x, double y, const string& text_to_write)
// Example:
Image my_image( Geometry(320,220), Color("white"));
list<Drawable> text_draw_list;
// set the text font: the font is specified via a string representing
// a fully qualified X font name (wildcards '*' are allowed)
text_draw_list.push_back(
DrawableFont("-misc-fixed-medium-o-semicondensed—13-*-*-*-c-60-iso8859-1"));
// set the text to be drawn at specified position: x=101, y=50 this case
text_draw_list.push_back( DrawableText(101, 50, "text to write on the canvas"));
// set the text color (the fill color must be set to transparent)
text_draw_list.push_back( DrawableStrokeColor(Color("black")));
text_draw_list.push_back( DrawableFillColor(Color(0, 0, 0, MaxRGB)));
// draw the "text to write on the canvas" string on the canvas with the above settings
my_image.draw( text_draw_list);
// Note: the red marking point in below image is located at position (100,50)
How can one pass a list like this?