Passing list to PythonMagick.Image.draw()

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
danielHeen
Posts: 28
Joined: 2010-03-18T06:34:34-07:00
Authentication code: 8675308
Location: Oslo, Norway

Passing list to PythonMagick.Image.draw()

Post 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
User avatar
danielHeen
Posts: 28
Joined: 2010-03-18T06:34:34-07:00
Authentication code: 8675308
Location: Oslo, Norway

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

Post 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
User avatar
danielHeen
Posts: 28
Joined: 2010-03-18T06:34:34-07:00
Authentication code: 8675308
Location: Oslo, Norway

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

Post 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?
Post Reply