开发者

adding text to image using python

开发者 https://www.devze.com 2023-01-12 10:31 出处:网络
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.

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()

pass

Thanks 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

0

精彩评论

暂无评论...
验证码 换一张
取 消