Page 1 of 1

add text problem

Posted: 2010-12-28T23:07:04-07:00
by ratneshsoni
i am having problem in creating text multiple words. like when i add 'abc' it fine but when i add 'abc xyz', in this case it only takes 'abc'.
i use this below code for doing this

convert -background none -fill '#000000' -font images/ttf_files/ARIALNI.TTF -pointsize 15 label:Ratnesh Soni \
images/textLarge/Ratneshd0292be4f764354efa2ac838c0051215.png

Re: add text problem

Posted: 2010-12-28T23:14:16-07:00
by anthony
You need to use quotes around your text, Otherwise the shell parser makes the two words two separate options (space separated). IM then thinks the second 'known' option is a filename and fails to find any such file!

Re: add text problem

Posted: 2010-12-29T02:38:57-07:00
by ratneshsoni
thanx it works fine but one more thing in case when i add stroke to text have same problem which i have earlier
the command i use is below

convert -size 200x500 xc:none -font images/ttf_files/ARIALNI.TTF -pointsize 15 -fill '#000000' \
-stroke '#3399CC' -strokewidth 2 -draw 'text 30,60 'Ratnesh Soni'' \
-stroke none -draw 'text 30,60 'Ratnesh Soni'' \
images/textLarge/Ratnesh Sonid0292be4f764354efa2ac838c0051215.png

Re: add text problem

Posted: 2010-12-29T04:01:55-07:00
by anthony
If you use -draw you need to use two layers of quoting. BOTH layers much also end.
The first layer is for the command line shell so the quoted string is kept together. The second layer is given to IM to mark the actaul string to be "rendered" onto the image.

This is easiest when the two layers use DIFFERENT quotes. As such you need to use

Code: Select all

-draw "text 30,60 'Ratnesh Soni' "
In this case the shell parses this as two arguments. -draw and the string text 30,60 'Ratnesh Soni' with the outside quotes removed.

You can however use the same quote if you tell the shell that the internal quotes do not end the argument, but is just a quote character which is part of the argument. (double is easier for this). For example

Code: Select all

-draw "text 30,60 \"Ratnesh Soni\" "
The shell passes the string argument as text 30,60 "Ratnesh Soni" Note that not only was the outside quotes removed but the backslashes inside the sting (protecting the inside quotes) are also removed. This is normal double quote shell handling.

Read about Shell Quoting (google for it) for more information.

For more details of using quotes with -draw see To Quote or Backslash?

The easier was is to use -annotate instead of draw as it only needs ONE layer of quoting (for the shell only)
See http://www.imagemagick.org/Usage/text/#annotateAnnotate - Text Drawing Operator

Re: add text problem

Posted: 2010-12-30T22:04:19-07:00
by ratneshsoni
it not take text in newline. i am using textarea to wirte text.
plz help me

Re: add text problem

Posted: 2010-12-31T10:20:40-07:00
by fmw42
try \n for new line or use caption: rather than -draw

see http://www.imagemagick.org/Usage/text/

Re: add text problem

Posted: 2010-12-31T23:19:26-07:00
by ratneshsoni
but the main problem with is that i am using textarea or textbox write text and having button when user click on that it generate the text image.
I cant add \n in that help me

Re: add text problem

Posted: 2011-01-01T02:55:07-07:00
by Bonzo
This is not a php forum but a couple of suggestions for you to look into:
1/ Use caption as Fred suggests.

Code: Select all

<?php  
exec("convert -size 230x130 -background lightblue -font verdana.ttf -pointsize 25 \\ 
-gravity NorthWest caption:\"The quick red fox jumped over the lazy brown dog.\" \\ 
-flatten caption1.jpg"); 
?> 
2/ Get the users to add <br> or a character e.g. | where they want an end of line and convert that to \\n
3/ Use Wordwrap and convert the character which wordwrap uses to \\n

Re: add text problem

Posted: 2011-01-01T12:19:33-07:00
by fmw42
caption: will word wrap appropriately so that line feeds, carriage returns, new line characters are not needed. So take the text box data, strip any returns if necessary and just feed to caption:

Read http://www.imagemagick.org/Usage/text/#caption