Page 1 of 1

how to use caption and font at the same time?

Posted: 2008-08-22T09:33:17-07:00
by phedra
Hi!

I don't succeeded to use command I've seen in documentation with Imagick:

Code: Select all

convert -background lightblue  -fill blue  -font Corsiva -pointsize 36 \
          -size 320x   caption:'This is a very long caption line.' \
          caption.gif
It's precisely the font family, the font size and the caption I want to use at the same time with Imagick. I've find only one function to use caption : newpseudoImage. But this function doesn't use font family and font size. Font family can be used with an Imagick object with the method setFont, (with enforcement, it's true), but not the font size.

How should I do the same things than the command?

Someone has an idea to do this?

Please excuse-me for my english, that is not my native language...

Thanks.

Re: how to use caption and font at the same time?

Posted: 2008-08-25T06:35:01-07:00
by phedra
Hello!

I've forgotten something... I want to do the same as the command do with Imagick API.

Nobody to help me?
Tanks.

Re: how to use caption and font at the same time?

Posted: 2008-08-28T01:16:34-07:00
by mkoppanen
There is currently undocumented method in Imagick which is called setFont. If you call this before creating the caption it should affect the font.

Re: how to use caption and font at the same time?

Posted: 2008-09-01T00:40:17-07:00
by phedra
I have read somewhere that we can use the method setFont with the Imagick class, but not setFontSize. I found in documentations and tutorials (and with some tests) that it can only be used with the Draw Class. Or, it seems this class does not affect the newPseudoImage method of the Imagick Class.

In conclusion how can I use caption and define a fontSize at the same time? Are there some errors in what I said? Or there is something I don't see?

Thanks for your response Mikko.

Re: how to use caption and font at the same time?

Posted: 2008-09-03T05:17:04-07:00
by mkoppanen
Imagick::setPointSize might help you, I'll add those to documentation.

Re: how to use caption and font at the same time?

Posted: 2008-09-03T08:00:43-07:00
by phedra
Great! Thank you very much!

Re: how to use caption and font at the same time?

Posted: 2009-06-23T19:06:46-07:00
by robcolburn
Ok, say I've set the Resolution, Font, and PointSize. Is there a way for me to set the spacing between the lines, what CSS refers to as "line-height".

Image

somewhat simplified code snippet

Code: Select all

$font = "l_10646.ttf";
$fontsize = 12;
$color = "000000";
$bold = 1;
$x = 50;
$y = 100;
$w = 100;
$h = 100;
$text = "this is only a test";

		$txt = new Imagick();
		$txt->setBackgroundColor('transparent');
		$txt->setResolution(85,85);
		$txt->setFont($font);
		$txt->setPointSize($fontsize);
		#$txt->setFontWeight($bold);
		#$txt->setFillColor( '#'.$color ); //text-color
		$txt->newPseudoImage($lw,$h,"caption:".$text);
		$image->compositeImage($txt, Imagick::COMPOSITE_OVER, $x, $y);
		$txt->destroy();

Re: how to use caption and font at the same time?

Posted: 2009-06-24T06:07:44-07:00
by magick
The MagickCore API supports a DrawInfo interword-spacing attribute but not an innerline spacing. We could add it if there is a demand.

Re: how to use caption and font at the same time?

Posted: 2009-06-24T18:05:21-07:00
by robcolburn
My big problem was that I needed to do word-wrap and be able to predict the result. It seemed that the caption method was the only way to do word-wrapping. Unfortunately, using caption and point-size yield impredictable results with actual vertical spacing.

Imagick::annotateImage with font-size and inserted new-line characters yields much more predictable vertical-spacing results. So, I've converted my function to using ImagickDraw, and wrote a word-wrapping algorithm with some scraps I found online (as a side benefit, this allows me to select color easily).

I'll publish the functions in a fresh thread.