how to render a long text in an area with automatic wrap

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?".
Post Reply
artex
Posts: 4
Joined: 2015-04-03T14:50:29-07:00
Authentication code: 6789

how to render a long text in an area with automatic wrap

Post by artex »

Hello everyone,
with php I create this command for image composition that works. But I want to render the text in a box area of a width of 100px (es.).
Does anyone know tell me the parameters to give the text?

if I use-size parameter again for text area doesn't work

convert -size "500"x"500" xc:white -density "72"x"72" -units PixelsPerInch -draw "translate 0,0 image Over 0,0 425,425 "background.jpg"" -draw "translate 155,100 image Over 0,0 125,125 "image/sun.jpg"" -font "font_ttf/font_ttf/Helvetica.ttf" -pointsize "16" -fill "red" -draw "translate 130,240 text 0,0 'text i like wrap in a box area of 150px large!'" out.png

it is very urgent!

Tanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to render a long text in an area with automatic wrap

Post by snibgo »

"-draw text" doesn't word-wrap. "caption:" does. See http://www.imagemagick.org/Usage/text/
snibgo's IM pages: im.snibgo.com
artex
Posts: 4
Joined: 2015-04-03T14:50:29-07:00
Authentication code: 6789

Re: how to render a long text in an area with automatic wrap

Post by artex »

Thanks,
how I have to specify the size of the box where render the text (es. 150 pixel large) ?

If I repeat -size parameter does'nt works.

Can you hlp me?

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to render a long text in an area with automatic wrap

Post by fmw42 »

try

Code: Select all

convert -background none -size 150x -fill black -font yourfont -pointsize PP caption:"your text here" result.png
Then composite this over your background image at the desired locations using -gravity and -geometry

Code: Select all

convert backgroundimage result.png -gravity ZZ -geometry +X+Y -compose over -composite finalresultimage
See
http://www.imagemagick.org/Usage/text/#caption
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/annotating/#gravity
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/script/comma ... hp#gravity
artex
Posts: 4
Joined: 2015-04-03T14:50:29-07:00
Authentication code: 6789

Re: how to render a long text in an area with automatic wrap

Post by artex »

my I use -size parameter two time?

After your indication i have tried:

convert -size "500"x"500" xc:white -density "72"x"72" -units PixelsPerInch -draw "translate 0,0 image Over 0,0 425,425 "background.jpg"" -draw "translate 155,100 image Over 0,0 125,125 "image/sun.jpg"" -font "font_ttf/font_ttf/Helvetica.ttf" -pointsize "16" -fill "red" -draw "translate 130,240 -size 150x caption: 'text i like wrap in a box area of 150px large!'" out.png

but does'nt works.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how to render a long text in an area with automatic wrap

Post by Bonzo »

but does'nt works.
I am not surprised; I would work on one step at a time and when that works move onto the next - you have so many things going on it would be very hard to debug.

You will also need to use parenthesis to group certain options.

It would be a good idea to link to an expected final output image so we know what you actually want.
artex
Posts: 4
Joined: 2015-04-03T14:50:29-07:00
Authentication code: 6789

Re: how to render a long text in an area with automatic wrap

Post by artex »

But I start by a comand that works:

convert -size "500"x"500" xc:white -density "72"x"72" -units PixelsPerInch -draw "translate 0,0 image Over 0,0 425,425 "background.jpg"" -draw "translate 155,100 image Over 0,0 125,125 "image/sun.jpg"" -font "font_ttf/font_ttf/Helvetica.ttf" -pointsize "16" -fill "red" -draw "translate 130,240 text 0,0 'text i like wrap in a box area of 150px large!'" out.png

do you kow how insert caption parameter with -size in my comand?

(I have seen parenthesis link)

thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to render a long text in an area with automatic wrap

Post by fmw42 »

You need to learn to use parenthesis processing so that the arguments do not apply repeatedly to the wrong part of the code. Also break long commands into newlines using a trailing \ at the end of the section so that the code is readable. See http://www.imagemagick.org/Usage/basics/#parenthesis.

-draw does not word wrap. you need to use caption and -size=Wx (not -size=WxH). See http://www.imagemagick.org/Usage/text/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to render a long text in an area with automatic wrap

Post by snibgo »

artex wrote:-draw "translate 130,240 -size 150x caption: 'text i like wrap in a box area of 150px large!'"
The syntax is wrong. "caption:" is not a valid option for "-draw".
snibgo's IM pages: im.snibgo.com
Post Reply