python报告水印怎么弄_python添加水印

#coding:utf-8

from PIL importImage, ImageDraw, ImageFontdefadd_text_to_image(image, text):

font= ImageFont.truetype('C:\Windows\Fonts\STXINGKA.TTF', 36)#添加背景

new_img = Image.new('RGBA', (image.size[0] * 3, image.size[1] * 3), (0, 0, 0, 0))

new_img.paste(image, image.size)#添加水印

font_len =len(text)

rgba_image= new_img.convert('RGBA')

text_overlay= Image.new('RGBA', rgba_image.size, (255, 255, 255, 0))

image_draw=ImageDraw.Draw(text_overlay)for i in range(0, rgba_image.size[0], font_len*40+100):for j in range(0, rgba_image.size[1], 200):

image_draw.text((i, j), text, font=font, fill=(0, 0, 0, 50))

text_overlay= text_overlay.rotate(-45)

image_with_text=Image.alpha_composite(rgba_image, text_overlay)#裁切图片

image_with_text = image_with_text.crop((image.size[0], image.size[1], image.size[0] * 2, image.size[1] * 2))returnimage_with_textif __name__ == '__main__':

img= Image.open("test.jpg")

im_after= add_text_to_image(img, u'石家庄')

im_after.save(u'水印.png')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值