Set draw text to the right

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
AcsPrime
Posts: 5
Joined: 2014-07-29T08:13:52-07:00
Authentication code: 6789

Set draw text to the right

Post by AcsPrime »

Hey guys.

I am new to image magick.
I am trying to create an image with some text aligned left some aligned right.
This is the code I have to create the image

Code: Select all

convert -fill black -size 450x150 xc:white \
Then I add the text.
The ones on the left are easy. I just do (in the convert command);
-pointsize 17 -draw "text 5,50 'Text text'" \

But I am having a hard time with the ones on the right.
I don't know the size of the text beforehand so how can I properly align the text to the right? (I need to align it vertically as well)

Thanks

EDIT:

Nevermind. The -gravity option was what I wanted.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Set draw text to the right

Post by fmw42 »

use -gravity. then the coordinates should be relative to the gravity setting. So if you use -gravity east, or northeast, then the x=0 will be relative to the right side.

see
http://www.imagemagick.org/script/comma ... hp#gravity
http://www.imagemagick.org/Usage/text/#draw

You can also use -annotate similarly with gravity. see
http://www.imagemagick.org/Usage/text/#annotate

Alternately, you can create a transparent background image which just surrounds your text and then composite it over your background image at any position via -gravity and -geometry. see label: or caption: on the same pages.
Post Reply