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
how can I best fit (largest possible) text in a rectangle box?
-
- Posts: 5
- Joined: 2016-04-05T12:09:53-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how can I best fit (largest possible) text in a rectangle box?
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.
Please always provide your IM version and platform, since syntax may differ.
-
- Posts: 5
- Joined: 2016-04-05T12:09:53-07:00
- Authentication code: 1151
Re: how can I best fit (largest possible) text in a rectangle box?
@fmw42: what code it is .. its not php? can you give me some idea?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how can I best fit (largest possible) text in a rectangle box?
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:
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
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>";}
?>
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