how to use caption and font at the same time?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
phedra

how to use caption and font at the same time?

Post 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.
phedra

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

Post 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.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

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

Post 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.
Mikko Koppanen
My blog: http://valokuva.org
phedra

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

Post 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.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

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

Post by mkoppanen »

Imagick::setPointSize might help you, I'll add those to documentation.
Mikko Koppanen
My blog: http://valokuva.org
phedra

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

Post by phedra »

Great! Thank you very much!
robcolburn

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

Post 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();
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
robcolburn

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

Post 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.
Post Reply