Page 1 of 1

Vertical alignment of text

Posted: 2011-04-21T04:11:20-07:00
by Santa911
I wish to use IM to write text (month names) on some pictures using commandlines. I would like the text to be rotated 270 degrees and placed to the left on the picture. My problem is that I can't figure out how to center the text vertically. The problem is that the lenght of the text is not the same, eg. May and September so I can't use offset.

I have no problem using the code "-gravity West" when the text is not rotated, but the text is not centered when rotated 270 degrees eg. "-annotate 270 February".

Can somebody help me with relevant code?

Lars

Re: Vertical alignment of text

Posted: 2011-04-21T04:49:46-07:00
by Bonzo
I would generate the text as an image and then put it on the photo. There can be a problem using -gravity on the text then locating an image using -gravity so may need to be done in two commands.

Untested and avoids using -gravity in the text generation:

Code: Select all

convert photo.jpg -gravity west ( -size 50x100 xc:none -fill black -annotate 90 "April" -trim ) -composite +repage output.jpg

Re: Vertical alignment of text

Posted: 2011-04-21T05:02:31-07:00
by anthony
As you are rotating all the text 270 degrees, why not just generate the text normally (center aligned or otherwise) then rotate the resulting image before overlaying on the background image.

Re: Vertical alignment of text

Posted: 2011-04-22T13:56:12-07:00
by Santa911
Thank you for your constructive input. I have tried to work with it, but I run into problems. The suggested commandline:
convert photo.jpg -gravity west ( -size 400x1200 xc:green -fill black -pointsize 120 -annotate 90 "September" -trim ) -composite +repage output.jpg
gives the result shown here:
http://www.dummyweb.dk/Temp/outputEx0.jpg

I have problems moving the text/image a bit further to the right. I would like to have this result (without the red color...):
http://www.dummyweb.dk/Temp/outputEx4.jpg

This however I can only get to work with this command which is not general:
convert photo.jpg -gravity west ( -size 1200x1200 xc:red -fill black -pointsize 150 -geometry -900+0 -gravity center -annotate 270 "September" -trim ) -composite +repage output.jpg

If the picture has a different size then the -geometry -900+0 is a bad solution. However I can't get this to work:
convert photo.jpg -gravity west -geometry +200+0 ( -size 1200x1200 xc:red -fill black -pointsize 150 -gravity center -annotate 270 "September" -trim )
-composite +repage output.jpg
It gives me this result:
http://www.dummyweb.dk/Temp/outputEx5.jpg

Hope somebody can help me with moving the text/picture a bit from the "west gravity"

Lars

Re: Vertical alignment of text

Posted: 2011-04-22T14:44:58-07:00
by fmw42
Your pointsize is too big for the size you specified. Better to let label: determine the best pointsize by only specifying one size and leaving off pointsize. Also you need to specify -gravity and -geometry after the overlay image in a convert ... -composite.

Try this and adjust the -size and -geometry to suit.


convert input ( -size 600x -background red -fill black label:"September" -rotate 90 -trim +repage ) -gravity west -geometry +20+0 -composite output


Also you might like to try this as an alternate to get the text vertically stacked using line feeds between characters.

convert input ( -size x600 -background red -fill black -gravity center label:"S\ne\np\nt\ne\nm\nb\ne\nr" -trim +repage ) -gravity west -geometry +20+0 -composite output

Re: Vertical alignment of text

Posted: 2011-04-27T05:32:25-07:00
by Santa911
I got it to work now with all your help.

My result for a photocalender now looks like this:

http://www.dummyweb.dk/Temp/DummyKalender2011-02.jpg

Thank you for all your help - it was very useful :-)

Lars

Re: Vertical alignment of text

Posted: 2011-04-27T07:56:31-07:00
by Bonzo
Thanks for the link Lars as its good to see the final result.

Re: Vertical alignment of text

Posted: 2011-04-28T16:52:06-07:00
by anthony
There is a small sed-tr script in the example shown in
IM Examples, Text Handling, Vertical Labels
http://www.imagemagick.org/Usage/text/#label_vertical
which will insert a newline character between every letter. Also note the use of gravity center too.

However I see from your 'final result' that you just decided to rotate the month name, instead of using a vertical stack