How to change font direction?

D

Daniel Mark

Hello all:

I am using PIL to draw some graphics and I need to draw some texts
in vertical direction rather than the default left-to-right horizontal
direction.

Is there anyway I could do that?


Thank you
-Daniel
 
T

theju

Well here are some self explanatory functions that I've written for
displaying the text vertically and from right to left. As for rotation
gimme some more time and i'll come back to you. Also I don't guarantee
that this is the best method(cos I myself am a newbie), but I can
guarantee you that it works.
Here it goes...

im=Image.open("imgfile.jpg")
draw=ImageDraw.Draw(im)

def verdraw(width,height,spacing,a="Defaulttext"):
for i in range(0,len(a)):
draw.text((width,height),a,(<options>))
height+=spacing

def right2leftdraw(width,height,spacing,a="Defaulttext"):
for i in range(0,len(a)):
draw.text((width,height),a[len(a)-i-1],(<options>))
width += spacing

<options> is a 3 field length tuple is mentioned in the PIL-Handbook.
Hope you find it useful
-Theju
 
F

Frederic Rentsch

theju said:
Well here are some self explanatory functions that I've written for
displaying the text vertically and from right to left. As for rotation
gimme some more time and i'll come back to you. Also I don't guarantee
that this is the best method(cos I myself am a newbie), but I can
guarantee you that it works.
Here it goes...

im=Image.open("imgfile.jpg")
draw=ImageDraw.Draw(im)

def verdraw(width,height,spacing,a="Defaulttext"):
for i in range(0,len(a)):
draw.text((width,height),a,(<options>))
height+=spacing

def right2leftdraw(width,height,spacing,a="Defaulttext"):
for i in range(0,len(a)):
draw.text((width,height),a[len(a)-i-1],(<options>))
width += spacing

<options> is a 3 field length tuple is mentioned in the PIL-Handbook.
Hope you find it useful
-Theju

Daniel said:
Hello all:

I am using PIL to draw some graphics and I need to draw some texts
in vertical direction rather than the default left-to-right horizontal
direction.

Is there anyway I could do that?


Thank you
-Daniel


I have done a circular 24-hour dial with the numbers arranged to read
upright as seen from the center. I remember writing each number into a
frame, rotating the frame and pasting it into the dial image at the
right place. I also remember using a transparency mask, so the white
background of the little frame didn't cover up what it happened to
overlap (minute marks). The numbers were black on white, so the frame
was monochrome and could be used as its own transparency mask.
(This could well be an needlessly complicated approach. When
confronting a problem, I tend to weigh the estimated time of hacking
against the estimated time of shopping and reading recipes and often
decide for hacking as the faster alternative.)

Regards

Frederic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top