Pillow制作斜体字水印

im = Image.open('my_pic.png')

    w, h = im.size

    watermark = Image.new('RGBA', im.size) # 水印

    draw = ImageDraw.Draw(watermark, 'RGBA')

    font_size = 10
    # 的哥是字体
    font = ImageFont.truetype(font='思源宋体TC-Regular.otf', size=font_size, layout_engine=ImageFont.LAYOUT_RAQM)

    # x y 坐标
    draw.text((0, 0), '这是水印内容', font=font, fill="#ff0000")
    # 旋转45度 
    watermark = watermark.rotate(-45, Image.BICUBIC)
    # 透明的
    alpha = watermark.split()[3]
    alpha = ImageEnhance.Brightness(alpha).enhance(0.7)
    watermark.putalpha(alpha)

    # 合成新的图片
    n = Image.composite(watermark, im, watermark)
    n.save('new_watermark.png', 'PNG')
声明:原创文章,版权所有,转载请注明出处,https://litets.com。