博客
关于我
Python IPL
阅读量:803 次
发布时间:2023-03-05

本文共 827 字,大约阅读时间需要 2 分钟。

如何在图片中添加文字水印并同时添加图片水印?以下是一些使用Python的步骤说明。

在图片中添加文字水印

首先,我们需要导入所需的模块:

from PIL import Image, ImageFont, ImageDraw

然后,打开图片文件:

img = Image.open("12.png")

接下来,加载字体文件并设置字体大小:

fnt = ImageFont.truetype("PingFang-SC-Regular.ttf", 60)

最后,在指定位置添加文字水印:

draw = ImageDraw.Draw(img)draw.text((10, 25), u"测试Hello ~!~~~!~!@~~!", font=fnt, fill="yellow")

这样,你就可以将文字水印添加到图片中了。最后可以通过img.show()查看图片,并使用img.save("1234.png", "png")保存修改后的图片。

同时添加文字水印和图片水印

如果你想在图片中同时显示文字水印和图片水印,可以按照以下步骤操作:

首先,打开图片文件并创建一个透明的背景层:

img_mark = Image.open("water.png")layer = Image.new('RGBA', img.size, (0,0,0,0))

然后,将图片水印添加到背景层中:

layer.paste(img_mark, (img.size[0]-150, img.size[1]-60))

最后,使用Image.composite函数合成两张图片:

out = Image.composite(layer, img, layer)

这样,你就可以同时看到文字水印和图片水印了。最后可以通过out.show()查看结果,并使用out.save("1234.png", "png")保存修改后的图片。

通过以上方法,你可以轻松地在图片中添加文字水印和图片水印。

转载地址:http://daafk.baihongyu.com/

你可能感兴趣的文章
python | awswrangler,一个高效的 Python 库!
查看>>
python | bashplotlib,一个有趣的Python库!
查看>>
python | bentoml,一个超级厉害的 模型部署 Python 库!
查看>>
python调用jar包的模块_python调用jar包
查看>>
python | black,一个神奇的 代码格式化工具 Python 库!
查看>>
python | bleach,一个超强的 Python 库!
查看>>
python | cartopy,一个有趣的 Python 库!
查看>>
python | cloud-init,一个实用的 云计算 Python 库!
查看>>
python | code2flow,一个神奇的 Python 库!
查看>>
python | cudf,一个超实用的 Python 库!
查看>>
python | daphne,一个非常nice的 Python 库!
查看>>
python调用halcon
查看>>
python | doit,一个非常实用的 Python 库!
查看>>
python | easyocr,一个超厉害的 关于OCR的 Python 库!
查看>>
python | fastFM,一个高级的 Python 库!
查看>>
python | feature_engine,一个实用的 Python 库!
查看>>
python | filelock,一个超酷的 Python 库!
查看>>
python | fire,一个强大的 Python 库!
查看>>
python | flanker,一个神奇的 Python 库!
查看>>
python | flower,一个强大的 Python 库!
查看>>