add text problem

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
ratneshsoni
Posts: 38
Joined: 2010-12-14T03:56:10-07:00
Authentication code: 8675308

add text problem

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: add text problem

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ratneshsoni
Posts: 38
Joined: 2010-12-14T03:56:10-07:00
Authentication code: 8675308

Re: add text problem

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: add text problem

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ratneshsoni
Posts: 38
Joined: 2010-12-14T03:56:10-07:00
Authentication code: 8675308

Re: add text problem

Post by ratneshsoni »

it not take text in newline. i am using textarea to wirte text.
plz help me
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: add text problem

Post by fmw42 »

try \n for new line or use caption: rather than -draw

see http://www.imagemagick.org/Usage/text/
ratneshsoni
Posts: 38
Joined: 2010-12-14T03:56:10-07:00
Authentication code: 8675308

Re: add text problem

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: add text problem

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: add text problem

Post 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
Post Reply