translating a command line to magick++ concerning pattern

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
milkyjing
Posts: 4
Joined: 2012-01-31T22:16:49-07:00
Authentication code: 8675308

translating a command line to magick++ concerning pattern

Post 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
milkyjing
Posts: 4
Joined: 2012-01-31T22:16:49-07:00
Authentication code: 8675308

Re: translating a command line to magick++ concerning patter

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: translating a command line to magick++ concerning patter

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
milkyjing
Posts: 4
Joined: 2012-01-31T22:16:49-07:00
Authentication code: 8675308

Re: translating a command line to magick++ concerning patter

Post 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 :D

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
Image
compared to
Image
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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: translating a command line to magick++ concerning patter

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
milkyjing
Posts: 4
Joined: 2012-01-31T22:16:49-07:00
Authentication code: 8675308

Re: translating a command line to magick++ concerning patter

Post 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

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++).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: translating a command line to magick++ concerning patter

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: translating a command line to magick++ concerning patter

Post 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. :P
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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply