Page 1 of 1
Need help re-writing convert command to Wand API
Posted: 2007-11-13T13:45:20-07:00
by RobertAnthony
Wand Gurus,
Is there a straightforward way of converting the following command into wand API equivalent ?
convert -background none -gravity center -fill black -font Arial -size 170x170 -rotate -5 -stroke none caption:Hello +size background_image.jpg +swap -gravity northwest -geometry +0+0 -composite out.jpg
Regards,
-Robert
Re: Need help re-writing convert command to Wand API
Posted: 2007-11-13T14:02:23-07:00
by magick
Most command line options have a Wand analog. For example, -rotate translates to
- MagickRotateImage( wand, 5.0 );
To read an image use MagickReadImage(). To set a font, use MagickSetFont(). Have fun.
Re: Need help re-writing convert command to Wand API
Posted: 2007-11-14T23:40:13-07:00
by RobertAnthony
magick wrote:Most command line options have a Wand analog. For example, -rotate translates to
- MagickRotateImage( wand, 5.0 );
To read an image use MagickReadImage(). To set a font, use MagickSetFont(). Have fun.
Thanks. That's a start. I have managed to get a little further, but I am still not able to get the same result.
The convert command I am trying to implement can be broken down into:
1) Create blank image, size=170x170, background = none, gravity=center, caption="Hello", font=XYZ, rotation=-5, disable sizing of caption so that text size is maximized, set stroke
2) Read existing image, set gravity to NorthWest, offset 0+0
3) Compose 1 over 2 (so I guess swap should happen before compose?)
4) Write image out
What is the best way to create an image using auto-sized caption ?
Re: Need help re-writing convert command to Wand API
Posted: 2007-11-15T01:42:32-07:00
by RobertAnthony
I think I finally got it. The code also passes the thread test, which makes it a lot better alternative. The only problem remaining is that the text is not centered.
What can be done to the Magick wand so that the caption that is read is is centered ?
Code: Select all
MagickWandGenesis();
wand=NewMagickWand();
bgwand=NewMagickWand();
MagickSetBackgroundColor(wand, c_none);
MagickSetFont(wand, font);
MagickSetSize(wand, text_width, text_height);
MagickReadImage(wand, "caption:This should be centered");
MagickRotateImage(wand, c_none, -5.0);
MagickReadImage(bgwand, "bg.jpg");
MagickCompositeImage(bgwand, wand, OverCompositeOp, 10, 10);
MagickWriteImages(bgwand, argv[24], MagickTrue);
// Cleanup...
MagickWandTerminus();
Re: Need help re-writing convert command to Wand API
Posted: 2007-11-15T07:59:53-07:00
by magick
We will add a new method, MagickSetGravity(), to set the image gravity. In the mean-time use MagickSetOption(wand,"gravity","center") before the image is read.
Re: Need help re-writing convert command to Wand API
Posted: 2007-11-15T09:39:34-07:00
by RobertAnthony
magick wrote:We will add a new method, MagickSetGravity(), to set the image gravity. In the mean-time use MagickSetOption(wand,"gravity","center") before the image is read.
That worked! Thanks for all your help.