How I can use Line Break like this with imagemagick

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How I can use Line Break like this with imagemagick

Post by snibgo »

I have updated my http://im.snibgo.com/snutf8.htm page to include Arabic examples, including word wrap and \n newlines.
snibgo's IM pages: im.snibgo.com
mostafanastary
Posts: 44
Joined: 2014-11-28T16:19:41-07:00
Authentication code: 6789

Re: How I can use Line Break like this with imagemagick

Post by mostafanastary »

Hi again,
i coding

$text = "I am not sure I understand your problem and the reference you provided. If it has to do with UTF8 characters, I believe you asked that before and got answers.";

$arrText=explode("\n",wordwrap($text,30,"\n"));

exec("convert -background white -gravity center -fill black -font tahoma.ttf -pointsize 18 -interline-spacing 10 label:$arrText[1] result.gif");

echo print_r($arrText);
echo printf($arrText);

when i print_r the $arrText Array, it echo:
Array ( [0] => I am not sure I understand [1] => your problem and the reference [2] => you provided. If it has to do [3] => with UTF8 characters, I [4] => believe you asked that before [5] => and got answers. )1

but result.gif is one word. i hope that draw """""your problem and the reference"""" in result as i point to $arrText[1] in exec command.
why? where is the problem?

Result:
Image

PS: i try "caption" too,
Last edited by mostafanastary on 2014-12-02T18:19:40-07:00, edited 1 time in total.
mostafanastary
Posts: 44
Joined: 2014-11-28T16:19:41-07:00
Authentication code: 6789

Re: How I can use Line Break like this with imagemagick

Post by mostafanastary »

I have updated my http://im.snibgo.com/snutf8.htm page to include Arabic examples, including word wrap and \n newlines.
that good, but you use the pango, is it safe for server? because last update of pango in it website is too old
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How I can use Line Break like this with imagemagick

Post by fmw42 »

exec("convert -background white -gravity center -fill black -font tahoma.ttf -pointsize 18 -interline-spacing 10 label:$arrText[1] result.gif");

label: does not word wrap. And if you want all the text in $arrText[1], you need to put it in quotes, otherwise you get just the first word.

If you want word wrap, then you need to use caption: or pango: and specify some width with -size Wx. You can leave out height H, but you need the x. But caption does not seem to work reliably to word wrap with Arabic font and pango does word wrap, but does not center well. See snibgo's link above for examples.
mostafanastary
Posts: 44
Joined: 2014-11-28T16:19:41-07:00
Authentication code: 6789

Re: How I can use Line Break like this with imagemagick

Post by mostafanastary »

Hi Fred, I code this command and it work very well. i test it with my new way for persian and arabic drawing text and work very good,

$text = 'I am not sure I understand your problem and the reference you provided. If it has to do with UTF8 characters, I believe you asked that before and got answers.';

$arrText=explode("\n",wordwrap($text,30,"\n"));
$n=0;
foreach($arrText as $arr)
{
exec("convert -background lightblue -fill blue -font tahoma.ttf -pointsize 36 -size 320x caption:'$arrText[$n]' result$n.png");
$n++;
}
this create result0.png,result1.png,and etc as $arr .
Post Reply