random textimage
gert
gert.cuykens at gmail.com
Wed Feb 28 06:39:37 EST 2007
On Feb 28, 12:13 pm, James Stroud <jstr... at mbi.ucla.edu> wrote:
> gert wrote:
> > gert at gert:~/Desktop/svn/xhtml$ python2.5 textimg.py
> > Traceback (most recent call last):
> > File "textimg.py", line 27, in <module>
> > print gen()
> > File "textimg.py", line 22, in gen
> > f.write(im)
> > TypeError: argument 1 must be string or read-only character buffer,
> > not instance
> > gert at gert:~/Desktop/svn/xhtml$
>
> > i am stuck anybody can help me ?
>
> Are you sure you don't want f.write(img) ?
>
> James
no this seems to work lol :)
import ImageFont, ImageDraw, Image
def gen(text):
image_file = "test.jpg"
image = Image.open(image_file)
font = "font.ttf"
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font, 12)
draw.text((1, 1), text,font=font)
image.save("temp.jpg")
if __name__ == "__main__":
import random
print gen(str(random.randint(0,1000)))
The next problem would be that i need this to work <img
src=randomtext.py/> in cherrypy because if two persons login at the
same time the first user get to see the second user textimage DOH!
More information about the Python-list
mailing list