Text to JPG. How to
Max M
maxm at mxm.dk
Wed Feb 5 05:23:01 EST 2003
vector wrote:
> Still new at this and just wondering if I should pursue this little side
> project using Python.
>
> Objective:
> request text from user via gui(tk entry box)
> convert text into a jpg (160x120 lowres)
> save jpg
This is some code I have that works:
########################3
buttonList = {}
buttonList['test1.gif'] = 'Test 1'
buttonList['test2.gif'] = 'Test 2'
import ImageDraw, ImageFont
import Image
# Set font
arial =
ImageFont.load('C:/root/pythonScripts/PILTest/phontz/Verdana_12_100.pil')
im = Image.open("C:/root/pythonScripts/PILTest/redButton.gif")
width, height = im.size
middle = width/2
for fileName, theText in buttonList.items():
aCopy = im.copy()
# render the text
draw = ImageDraw.Draw(aCopy)
draw.setfont(arial)
draw.setink(255)
textWidth, textHeight = draw.textsize(theText)
textMiddle = textWidth/2
fontPlacement = middle - textMiddle
print textWidth
draw.text((fontPlacement, -3), theText)
aCopy.save('C:/root/pythonScripts/PILTest/' + fileName)
--
hilsen/regards Max M Rasmussen, Denmark
http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme
More information about the Python-list
mailing list