Page 1 of 2

How I can use Line Break like this with imagemagick

Posted: 2014-12-01T13:22:03-07:00
by mostafanastary
Hi,
i found http://stackoverflow.com/questions/3577 ... magemagick

and it have

$draw = new ImagickDraw();
$x = 0;
$y=20;
$angle = 0;
$padding = 10;
$str = "some text for testing of a word wrap in imagemagick";
$str = wordwrap($str, 10,"\r");
$str_array = explode("\n",$str);
foreach($str_array as $line)
$im->annotateImage( $draw, $x, $y+$padding, $angle, $line );
}

to line break, I need to use this code with php and imagemagick and exec command.

any help please?

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

Posted: 2014-12-01T14:15:16-07:00
by fmw42
This code is using Imagick API. It is not directly usable for PHP exec(). You would have to create the equivalent command line code with unix shell or windows batch script to do the looping and extract each word from the list.

This is a simple solution:

Code: Select all

convert -background white -gravity center -fill black -font Arial -pointsize 18 -interline-spacing 10 \
label:"some\ntext\nfor\ntesting\nof\na\nword\nwrap\nin\nimagemagick" result.gif
see
http://www.imagemagick.org/Usage/text/# ... ne-spacing

change the -gravity to west if you want it aligned on the left side.

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

Posted: 2014-12-01T14:23:22-07:00
by mostafanastary
hi
i have problem like: viewtopic.php?t=19249
i do not want to use /n because i get the text from input form.also i need to change something , but i can use the wordwrap to explode text with /n.

for example : I have a input like:
This code is using Imagick API. It is not directly usable for PHP . You would have to create the equivalent command line code with unix shell or windows batch script to do the looping and extract each word from the list.

i can explode /n it and my result will be:
line1 - This code is using Imagick API. It is not directly usable for PHP .
line2 - You would have to create the equivalent command line code with unix shell or
line3 - windows batch script to do the looping and extract each word from the list.

so i need to draw first line 3 then line 2 and then line1

is it possible?

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

Posted: 2014-12-01T15:32:27-07:00
by Bonzo

Code: Select all

$draw = new ImagickDraw();
 $x = 0;
 $y=20;
 $angle = 0;
 $padding = 10;
 $str = "some text for testing of a word wrap in imagemagick";
 $str = wordwrap($str, 10,"\r");
 $str_array = explode("\n",$str);
 foreach($str_array as $line)
 $im->annotateImage( $draw, $x, $y+$padding, $angle, $line );
 }
You can use most of the above code as it is; you need to create your canvas and then write the text. I would concat the text into a string in the foreach adding an -annotate +0+{$padding} to each new line and use that in your imagemagick command.

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

Posted: 2014-12-01T16:15:22-07:00
by fmw42
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.

If you do not want to manually insert \n, then you can automate that. Try this ($text can come from your form element). This is just PHP exec compatible. If you need to use Imagick, then do what user bonzo suggested above.

Code: Select all

$text="some text for testing of a word wrap in imagemagick"
$newtext=str_replace(" ", "\n", $text);
exec("convert -background white -gravity center -fill black -font Arial -pointsize 18 -interline-spacing 10 \
label:"."$newtext"." result.gif");
Some PHP expert should correct my quoting in the exec command if it is wrong.

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

Posted: 2014-12-01T16:22:30-07:00
by mostafanastary
Hi fred, you true, i got my answer, but this topic is about line auto break in imagemagick, thank you for answer and thanks bonzo.
i will try that.

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

Posted: 2014-12-01T16:57:14-07:00
by fmw42
You can do automatic line breaks (not word breaks) by using caption: or pango: instead of label:

see
http://www.imagemagick.org/Usage/text/#caption
http://www.imagemagick.org/Usage/text/#pango

try this:

Code: Select all

text="some text for testing of a word wrap in imagemagick"
convert -background white -size 200x -gravity center -fill black -font Arial -pointsize 18 -interline-spacing 10 \
caption:"$text" result.gif
You just need to specify the width and pointsize and IM will automatically break the line where needed.

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

Posted: 2014-12-01T17:20:48-07:00
by mostafanastary
it's true, but also i told already, in need draw lines, revers... first 3, then 2, then 1
i found a way to draw persian or arabic text without pango , just imagemagick and some php code, i will share that with imgaemaick ORG :) very soon,
i hope that use full.

best regards.

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

Posted: 2014-12-01T18:19:41-07:00
by fmw42
but also i told already, in need draw lines
I have no idea what lines you want to draw. If you mean rows of text, that is what caption: did. If you want to draw a word at a time, then the label process works just fine.

So I am not sure what kind of result you are trying to achieve.

If you have found a way to do that, then please show us your code and resulting image.

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

Posted: 2014-12-01T18:35:45-07:00
by mostafanastary
i mean row, in persian we say line :)

but the some result with : aban.ttf (farsi font ) and with imagemagick without pango or etc... :

Image

hejaz.ttf:

Image

ahmad.ttf:

Image


if let me, i share code on the end.

best regards.

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

Posted: 2014-12-01T18:56:46-07:00
by fmw42
mostafanastary wrote:i mean row, in persian we say line :)

but the some result with : aban.ttf (farsi font ) and with imagemagick without pango or etc... :

Image

hejaz.ttf:

Image

ahmad.ttf:

Image


if let me, i share code on the end.

best regards.

What does this have to do with your original question at the top of this topic, regarding the code you provided? Please keep the posts to one subject; otherwise, it gets very confusing for people to answer your questions. Did you resolve the original question?

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

Posted: 2014-12-01T19:01:51-07:00
by mostafanastary
but topic is about line break fred,
I open a new topic and explain about the code.
thank you

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

Posted: 2014-12-01T19:03:23-07:00
by mostafanastary
what is your idea about the results?

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

Posted: 2014-12-01T20:17:55-07:00
by fmw42
Sorry, I am confused. I do not see any line breaks in your examples above. So I do not connect those results to the title of your topic.

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

Posted: 2014-12-01T23:18:09-07:00
by snibgo
Pango wordwrap (automatic newlines) seems to work correctly for Arabic. For example (Windows BAT syntax):

Code: Select all

convert ^
  -size 200x200 -gravity Center ^
  -background khaki ^
  -font Arial -pointsize 50 ^
  pango:"صَوْرة سِحْر" ^
  u8_pa_a2ww.png
Image