tags:

views:

65

answers:

2

Is the following function correct, this code is meant to add a phrase to image. Note that i cannot use image.text function or any other but can only use getpixel, putpixel, load, and save.

def insertTxtImage(srcImage, phrase):
    pixel = srcImage.getpixel(30,30);
    srcImage.putpixel(pixel,phrase);
    srcImage.save;
pass

Yes it is homework which can only use getpixel, putpixel, load, and save to insert a phrase in to the image.

I tried to do this with this code but it is giving system error (argument is not a tuple)

def insertTxtImage(srcImage, phrase):
pix = srcImage.load()
pix[0,0] = phrase
srcImage.save()
pass

Thanks for the comments.

A: 

No, the functions you are using modify pixels.

To draw font you want to use something like following:

f= pygame.font.Font(None, 12)
surf= f.render(phrase)
srcImage.blit(surf, (30,30))

for more documentation see here: (scroll down a bit) http://www.pygame.org/docs/ref/font.html

EDIT: nvm, I don't even know what you're doing or trying to do

karpathy
A: 

try this http://www.pythonware.com/products/pil/

Gunslinger_