Python3 图片打水印详解编程语言

    from PIL import Image, ImageDraw, ImageFont   
    import os   
    def water_work(img):   
        x, y = img.size   
        textx = int(x*1.5)   
        texty = int(y*1.5)   
        blank = Image.new('RGB', (textx, texty), 'white')   
        draw = ImageDraw.Draw(blank)   
        font = ImageFont.truetype('simsun.ttc', size=50)   
        text = '王小涛_同學'   
        draw.ink = 100   
        draw.text(((textx-x/2)/2, (texty)/2), text, font=font)   
        One_blank = blank.rotate(30)   
        box = (730, 610, 1000, 800)   
        textImage = One_blank.crop(box)<img src="http://img.blog.csdn.net/20150208171613764" alt="" />   
        pastebox = (int(x/2 + 80), int(y/2))   
        blank2 = Image.new('RGB', (x, y), 'white')   
        blank2.paste(textImage, pastebox)   
        waterImage = Image.blend(img, blank2, 0.2)   #图片合并<img src="http://img.blog.csdn.net/20150208171708598" alt="" />   
        waterImage.save(image, quality=100)   
    for img in os.listdir('C:/Users/hengli/Pictures/lovewallpaper'):   
        if img.endswith('.jpg'):   
            image = os.path.join('C:/Users/hengli/Pictures/lovewallpaper/', img)   
            img = Image.open(image)   
            water_work(img)  

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8163.html

(0)
上一篇 2021年7月18日
下一篇 2021年7月18日

相关推荐

发表回复

登录后才能评论