Pango C API
Pango C API
I am using ImageMagick 6.8.9-10 on linux. I am using wands C API to do some image manipulations like adding text or overlaying another image.
For drawing text I was using DrawAnnotate method, which works fine for english characters. Now as per the new requirement I want to add arabic text support as well, which annotate method is not able to do, so I searched regarding this and was able to write arabic text by using pango in the following way :
convert -size 400x200 -gravity Center -font DejaVu-Sans -pointsize 30 pango:@ar.txt pango_test.png
here my arabic text is present in ar.txt.
The problem is I am not able to fine the corresponding C API. Can someone point me to the same. Any help is appreciated.
For drawing text I was using DrawAnnotate method, which works fine for english characters. Now as per the new requirement I want to add arabic text support as well, which annotate method is not able to do, so I searched regarding this and was able to write arabic text by using pango in the following way :
convert -size 400x200 -gravity Center -font DejaVu-Sans -pointsize 30 pango:@ar.txt pango_test.png
here my arabic text is present in ar.txt.
The problem is I am not able to fine the corresponding C API. Can someone point me to the same. Any help is appreciated.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Pango C API
MagickCore or MagickWand? Just use ReadImage() or MagickReadImage() in the usual way, with the filename "pango:@ar.txt".
snibgo's IM pages: im.snibgo.com
Re: Pango C API
MagickWand. But ar.txt is the file containing arabic text not the image.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Pango C API
Okay, MagickWand, so something like:
Code: Select all
MagickBooleanType status = MagickReadImage (magick_wand, "pango:@ar.txt");
snibgo's IM pages: im.snibgo.com
Re: Pango C API
But this will load this file's text as an image, how will we specify the font face, color & size to use for this?
Re: Pango C API
Apart from this is there any other method except Pango. Because I don't want to create a file of text everytime I want to draw some text. I want to use something like what annotate does. Is there any other method which will help me write arabic texts over an image?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Pango C API
You can specify those in the Pango file, or with IM facilities such as MagickSetPointsize().him21sri wrote:... how will we specify the font face, color & size to use for this?
You don't need to write a file, you can include the literal text in the MagickReadImage().
In my experiments, Pango seems to be the best option for Arabic. But these are only experiments. Your mileage may vary.
snibgo's IM pages: im.snibgo.com
Re: Pango C API
Sorry I am asking very basic questions here, but I think api for setting font size, font are all present as DrawingWand api not as MagickWand api. And if we load arabic text using MagickReadImage like :
MagickBooleanType status = MagickReadImage (magick_wand, "pango:صَوْرة سِحْر");
It will be loaded as an image and then how will I specify the font size and font name etc. as they are part of DrawingWand API and can only be applied on drawingWand not the magickWand. Please guide how can I proceed
MagickBooleanType status = MagickReadImage (magick_wand, "pango:صَوْرة سِحْر");
It will be loaded as an image and then how will I specify the font size and font name etc. as they are part of DrawingWand API and can only be applied on drawingWand not the magickWand. Please guide how can I proceed
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Pango C API
You are looking in the wrong place. I gave you an example: MagickSetPointsize() which takes a wand and a number as parameters. Naturally, this should be set before you read the pango:text.him21sri wrote:... but I think api for setting font size, font are all present as DrawingWand api not as MagickWand api.
To get you going, here is a complete v7 MagickWand program, wrpango.c. It sets the pointsize, font and fill colour internally. It needs the complete input name, and output name, as program arguments.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <MagickWand/MagickWand.h>
// A demonstration MagickWand program.
#define ThrowWandException(wand) \
{ \
char \
*description; \
\
ExceptionType \
severity; \
\
description=MagickGetException(wand,&severity); \
(void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
description=(char *) MagickRelinquishMemory(description); \
exit(-1); \
}
int main(int argc,char **argv)
{
MagickBooleanType
status;
MagickWand
*magick_wand;
if (argc != 3) {
fprintf(stdout,"Usage: %s text outfile\n",argv[0]);
exit(0);
}
MagickWandGenesis ();
magick_wand = NewMagickWand ();
MagickSetPointsize (magick_wand, 100);
MagickSetFont (magick_wand, "Arial");
MagickSetOption (magick_wand, "fill", "Red");
status = MagickReadImage (magick_wand, argv[1]);
if (status == MagickFalse)
ThrowWandException(magick_wand);
status=MagickWriteImages(magick_wand,argv[2],MagickTrue);
if (status == MagickFalse)
ThrowWandException(magick_wand);
magick_wand=DestroyMagickWand(magick_wand);
MagickWandTerminus();
return (0);
}
Code: Select all
wrpango "pango:Hello World" wrp_out.png
snibgo's IM pages: im.snibgo.com
Re: Pango C API
Thanks for your help I was able to draw arabic text. But I am having some other doubts here. I will explain what I want to do first, so there is one mainImage over which I want to overlay a secondaryImage on top of that secondaryImage I want to put some text. Earlier to put some text over a secondaryImage I was using DrawingWand API and annotate method to place the text and there I was able to specify gravity, font, color, point size and offset of text(DrawAnnotation method allows giving offsets as well). But as we know Annotate method doesn't work well with arabic text.
So when we use pango the text will be loaded in a tempWand which I will have to put on the secondaryImage, the problem with this is how will I control the gravity of the text on the secondaryImage and the offsets as well?
For overlaying a Image over another image I am using MagickCompositeImage method which excepts offsets but it will be difficult to control the offset say when I want to put text in the center of secondaryImage.
Please guide on the scenario described above.
Apart from this the above pasted code by you everything is working except the font color part. I used MagickSetOption as mentioned above but text always coming in black, I tried giving rgb values as well. And I output the result of MagickGetOption for "fill" key I was getting the value whatever I set. Still the text color didn't change.
So when we use pango the text will be loaded in a tempWand which I will have to put on the secondaryImage, the problem with this is how will I control the gravity of the text on the secondaryImage and the offsets as well?
For overlaying a Image over another image I am using MagickCompositeImage method which excepts offsets but it will be difficult to control the offset say when I want to put text in the center of secondaryImage.
Please guide on the scenario described above.
Apart from this the above pasted code by you everything is working except the font color part. I used MagickSetOption as mentioned above but text always coming in black, I tried giving rgb values as well. And I output the result of MagickGetOption for "fill" key I was getting the value whatever I set. Still the text color didn't change.
Re: Pango C API
I was able to solve the rest of my problem by calculating the offsets for MagickCompositeImage based on the required gravity, but I am stuck on getting the right font color. Please guide here. How can I pass the color for the texthim21sri wrote: ↑2017-06-27T23:19:10-07:00 Apart from this the above pasted code by you everything is working except the font color part. I used MagickSetOption as mentioned above but text always coming in black, I tried giving rgb values as well. And I output the result of MagickGetOption for "fill" key I was getting the value whatever I set. Still the text color didn't change.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Pango C API
I have shown you a complete program wrpango.c. It works for me, under v7.0.1-0 (which is now quite old), and under v6.9.3-7 after changing a line to "#include <wand/MagickWand.h>". I suggest you compile and run wrpango.c under your version, v6.8.9-10. Does it work?
If wrpango.c does work for you, then you may have a bug in your program. If you paste it here, I may be able to debug it.
If wrpango.c doesn't work for you, there may be a bug or feature in v6.8.9-10 that causes problems, and upgrading to current IM (v6 or v7) may help.
If wrpango.c does work for you, then you may have a bug in your program. If you paste it here, I may be able to debug it.
If wrpango.c doesn't work for you, there may be a bug or feature in v6.8.9-10 that causes problems, and upgrading to current IM (v6 or v7) may help.
snibgo's IM pages: im.snibgo.com
Re: Pango C API
I tried MagickSetOption(textWand, "background", "blue") this actually turned the background as blue. I am confused why "fill" is not working.
Re: Pango C API
Ok I managed to control color through foreground attribute of span tag. But I feel there is no effect of MagickSetFont here. Font don't seem to be changing, even if I put some random value then also no effect or no error is thrown.
Re: Pango C API
And can you also explain how pango does word wrap? what will i have to do so that it do word wrap