如何用python去除图片的logo_如何使用Python在图像上书写文本,并在图像上覆盖另一个图像?...

I need to put some text over a PNG image in Python, I need to put another image too over the first one.

So I'll have a base image (the same for every image created), a logo to put over it in the upper left corner, and a text all over the image (non-specific font, I just need to set the font size).

Could I use PIL, or another Library?

I searched over StackOverflow and Google too, but I could not find tips on how to do this.

Thanks.

解决方案

PIL can do it:

from PIL import Image, ImageFont, ImageDraw

font = ImageFont.truetype("/usr/share/fonts/dejavu/DejaVuSans.ttf", 25)

img = Image.new("RGBA", (200,200), (120,20,20))

draw = ImageDraw.Draw(img)

draw.text((0,0), "This is a test", (255,255,0), font=font)

draw = ImageDraw.Draw(img)

img.save("a_test.png")

The only error that can occur is not to find the font.

In this case you must change the code line:

font = ImageFont.truetype("/usr/share/fonts/dejavu/DejaVuSans.ttf",25)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值