Page 1 of 1

Text rotation problem

Posted: 2015-07-08T09:48:54-07:00
by grigory
Hey guys,

I use the following command to draw a couple of text strings on image:

Code: Select all

/usr/local/bin/convert /gifs/tmp/df47902.gif \( -font /fonts/Font.ttf -pointsize 30  -fill "#000000"  -draw "text 183,130 'text1'" -fill "#ff00ff"  -draw "text 181,128 'text1'" \) \( -font /fonts/Font.ttf -pointsize 30  -fill "#000000"  -draw "text 57,130 'text2'"  -fill "#00ffff"  -draw "text 55,128 'text2'" \) \( -font /fonts/Font.ttf -pointsize 30  -fill "#ff0000"  -draw "text 333,114 '
text3'" \) /gifs/res/tmp.gif
The command above prints 3 strings: text1 (with shadow), text2 (with shadow), text3 (without shadow).

I need to rotate THIRD string ('text3' with shadow), for example.
When I add "rotate -5" inside "-draw" section, it rotates okay but Y-coordinate is higher than expected. Seems like it has wrong gravity. But when I add "-gravity Center" it applies to all the strings I have (text1, text2, text3).

So... How to rotate only one string? And how to rotate it around first letter, for example?

Re: Text rotation problem

Posted: 2015-07-08T10:31:11-07:00
by snibgo
A "rotate" within the draw will rotate about the coordinate 0,0, so the entire text will "swing" around that coordinate. You can first translate to put the first character at 0,0, then rotate, then translate back. Within "-draw", the operations are written in the reverse order.

Code: Select all

convert \
  -size 600x400 xc:khaki \
  \( -pointsize 30  \
     -fill "#000000"  -draw "text 183,130 'text1'" \
     -fill "#ff00ff"  -draw "text 181,128 'text1'" \) \
  \( -pointsize 30 \
     -fill "#000000"  -draw "text 57,130 'text2'" \
     -fill "#00ffff"  -draw "text 55,128 'text2'" \) \
  \( -pointsize 30 \
     -fill "#ff0000" \
     -draw "translate 320,120 rotate 20 translate -320,-120 text 333,114 'text3'" \) \
  tmp.gif
Adjust each 320,120 as required.

Re: Text rotation problem

Posted: 2015-07-08T11:08:05-07:00
by fmw42
You might be better to use -annotate. It will allow rotation easier. See http://www.imagemagick.org/Usage/text/#annotate

Re: Text rotation problem

Posted: 2015-07-08T11:39:27-07:00
by grigory
This "translate" function works like a charm!
Thank you!