adding text to image using python
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(pi开发者_StackOverflow中文版xel,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() passThanks for the comments.
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
精彩评论