Text rotation problem

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
grigory
Posts: 15
Joined: 2015-05-24T05:48:35-07:00
Authentication code: 6789

Text rotation problem

Post 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?
Last edited by grigory on 2015-07-08T11:39:39-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text rotation problem

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text rotation problem

Post by fmw42 »

You might be better to use -annotate. It will allow rotation easier. See http://www.imagemagick.org/Usage/text/#annotate
grigory
Posts: 15
Joined: 2015-05-24T05:48:35-07:00
Authentication code: 6789

Re: Text rotation problem

Post by grigory »

This "translate" function works like a charm!
Thank you!
Post Reply