Page 1 of 1
how can I best fit (largest possible) text in a rectangle box?
Posted: 2016-04-22T09:44:29-07:00
by bikash00789
I am very new imagemagick in PHP code and I am trying to best fit (largest possible) in a rectangle box, width and height would be dynamically given, for now:100px , height:200px , depending on the string lenght it should best fit into it? I found lot of GD code but did not understand. Please help me on this?e on this?
http://stackoverflow.com/questions/1223 ... -rectangle
like this? but not able to put in imagemagick
Re: how can I best fit (largest possible) text in a rectangle box?
Posted: 2016-04-22T09:53:12-07:00
by fmw42
See label: or caption: or pango: at
http://www.imagemagick.org/Usage/text/
Please always provide your IM version and platform, since syntax may differ.
Re: how can I best fit (largest possible) text in a rectangle box?
Posted: 2016-04-22T09:59:24-07:00
by bikash00789
@fmw42: what code it is .. its not php? can you give me some idea?
Re: how can I best fit (largest possible) text in a rectangle box?
Posted: 2016-04-22T11:14:45-07:00
by fmw42
Imagemagick is not PHP code. It is command line based. You can, however, call the command line in PHP exec. Or you can use one of the PHP API programs, such as Imagick.
If you use PHP exec, you can do this, for example as:
Code: Select all
<?php
exec("path2/convert -size WxH -background somecolor -fill someothercolor -font path2/somefont.ttf caption:"Your Text Here" result.png 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
where WxH is your desired size, somecolor and someothercolor are any valid IM color and somefont.ttf is your desired font file.
see
http://www.imagemagick.org/Usage/text/#caption_bestfit and
http://www.imagemagick.org/script/color.php
If you want to use Imagick (PHP API), then see
http://us3.php.net/manual/en/book.imagick.php