Page 1 of 1
translating a command line to magick++ concerning pattern
Posted: 2012-01-31T22:36:03-07:00
by milkyjing
Hi there, I've got a problem when trying to translate a command line of IM to Magick++, though it is really a simple one:
Code: Select all
$ convert -size 640x480 pattern:checkerboard checkerboard.png
I can understand how this script functions, but just cannot find an alternative way of doing it using Magick++.
Can we do it in Magick++ in a relatively direct way, or have to code a lot to meet the same goal (as the command line version does)?
Any solutions/tips are warmly welcomed. And thanks in advance.
Regards,
milkyjing
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-01T03:20:36-07:00
by milkyjing
Well, after reading the article on 'How to ask questions the smart way'. I strongly feel the need to add some more stuffs, mainly my own thinking towards the question.
'-size' operator is one of the
'Input Settings', with '-size 640x480', the image read from 'patterns\checkerboard.png' will be used in some way (I couldn't figure out the detailed behavior) resulting a '640x480' checker board, and then saved to 'checkerboard.png'.
I've checked out the Magick++ documentations, but unfortunately didn't find the alternative way of doing the 'Input Settings' as IM command line does.
I've also had a look at the source code of 'convert.exe' hoping that I would learn the detailed behavior (specific APIs invoked from MagickCore), but without good luck.
So, any tips/hints/solutions will be appreciated.
Regards,
milkyjing
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-01T08:52:31-07:00
by el_supremo
Both of these are in C but you should be able to figure out how to do the same thing in Magick++
See the last piece of code posted by user "fisheggs" in this thread:
viewtopic.php?f=2&t=9346
And in my "MagickWand Examples in C", see the Pattern (second) text effect in "Eight text effects in one function"
http://members.shaw.ca/el.supremo/MagickWand/
Pete
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-01T19:40:34-07:00
by milkyjing
el_supremo wrote:Both of these are in C but you should be able to figure out how to do the same thing in Magick++
See the last piece of code posted by user "fisheggs" in this thread:
viewtopic.php?f=2&t=9346
And in my "MagickWand Examples in C", see the Pattern (second) text effect in "Eight text effects in one function"
http://members.shaw.ca/el.supremo/MagickWand/
Pete
Thanks Pete, you're nice
By following your tips, I finally figured it out, though still with some questions left.
First let me mention my solution, it's simple and got by chance:
Code: Select all
img = Image("640x480", "transparent")
img.read("pattern:checkerboard")
img.write("out_checkerboard.png")
I believe the read method behaves differently when given the parameter "pattern:checkerboard" other than "checkerboard.png", which I suppose is just the same with the IM command line does.
While experimenting I came up with a question. If I use
Code: Select all
img.fillPattern(Image("checkerboard.png"))
instead of
Code: Select all
img.fillPattern(Image("pattern:checkerboard"))
I got the following result
compared to
I am a little confused about the two behaviors, anyway I'll continue checking it out
The second question is in Magick++ I didn't find a DrawableSetFillPatternURL method. And I am not much clear about the definition of the first parameter (id_) of the DrawablePushPattern method. So I'm looking forward to having any relative tips/hints about the usage of DrawablePushPattern/DrawablePopPattern method in Magick++. Many thanks.
Regards,
milkyjing
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-02T13:58:52-07:00
by el_supremo
The basic pattern:checkerboard is designed to be tiled. But when you tile that image onto a 640x480 canvas, the result is not necessarily an image that can also be tiled. The left edge and the right edge of checkerboard.png don't match properly when tiled.
I'm not familair with Magick++ so I can't help with your question about DrawableSetFillPatternURL. Perhaps magick can help with this.
Pete
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-02T18:37:10-07:00
by milkyjing
el_supremo wrote:The basic pattern:checkerboard is designed to be tiled. But when you tile that image onto a 640x480 canvas, the result is not necessarily an image that can also be tiled. The left edge and the right edge of checkerboard.png don't match properly when tiled.
I'm not familair with Magick++ so I can't help with your question about DrawableSetFillPatternURL. Perhaps magick can help with this.
Pete
Thanks again Pete
So, you mean when we use 'pattern:checkerboard', the IM will generate (or use) a different image (internally) which can be tiled perfectly, while the checkerboard.png under the patterns folder seems not to be? Well it seems to be the only reasonable explanation, I tried removing the checkerboard.png but still we can use 'pattern:checkerboard' successfully.
p.s. Actually I am using the PythonMagick binding (due to some practical reasons), which has no documentation and seems to be lacking some features, so I am now having a hard time to get it work just like the command line approach. I try to translate some of the command line examples on the
http://www.imagemagick.org/Usage/ Webpage to learn how to use it. The best stuff I found is the Magick++ Documentation, which is fairly close to the python binding. But it is a pity that PythonMagick is a little bit 'incomplete' (when compared to Magick++).
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-02T19:10:55-07:00
by fmw42
So, you mean when we use 'pattern:checkerboard', the IM will generate (or use) a different image (internally) which can be tiled perfectly, while the checkerboard.png under the patterns folder seems not to be? Well it seems to be the only reasonable explanation, I tried removing the checkerboard.png but still we can use 'pattern:checkerboard' successfully.
The checkerboard.png image was not meant to be tiled. But you can create one for yourself from pattern:checkerboard that can be tiled by simply specifying the output image size to be a equal to or a whole number multiple of the base checkerboard pattern (30x30). See
http://www.imagemagick.org/script/forma ... n-patterns
Re: translating a command line to magick++ concerning patter
Posted: 2012-02-12T06:18:30-07:00
by anthony
milkyjing wrote:So, you mean when we use 'pattern:checkerboard', the IM will generate (or use) a different image (internally) which can be tiled perfectly, while the checkerboard.png under the patterns folder seems not to be? Well it seems to be the only reasonable explanation, I tried removing the checkerboard.png but still we can use 'pattern:checkerboard' successfully.
The "checkerboard.png" in the patterns folder, is there because it was built into IM during its compilation of the 'pattern:' coder, so that you can use 'pattern:checkerboard'. You can see its translation into a in-code GIF image 'blob' in coders/pattern.c
In a similar way some other images (like "rose:") are also built in for use as 'test images' in the file coders/magick.c