用python给照片添加水印的三种方式_python加水印-CSDN博客
方式三:filestools模块
filestools模块其本质上也是对ImageDraw.Draw.text()方法做了进一步的封装,让我们用起来会更加的简便,使用add_mark()方法可以生成数量较多的水印,该方法当中里面有8个参数,其中比较重要的几个是
mark:水印的文字内容
color、size、opacity、space、angle:水印文字的样式包括文字的大小、颜色、透明程度等等
from watermarker.marker import add_mark
add_mark(file = "test1.jpg", out = "add_mark_test1.jpg",
mark = "Python", opacity=0.2, angle=30, space=30)
安装时报错了
ERROR: Cannot install watermarker==1.0 and watermarker==1.1 because these package versions have conflicting dependencies.
The conflict is caused by:
watermarker 1.1 depends on pil
watermarker 1.0 depends on pil
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
从git上下载watermarker代码,然后集成到系统里面
GitHub - 2Dou/watermarker: 使用python脚本为图片添加文字水印
usage: marker.py [-h] [-f FILE] [-m MARK] [-o OUT] [-c COLOR] [-s SPACE] [-a ANGLE] [--font-family FONT_FAMILY] [--font-height-crop FONT_HEIGHT_CROP] [--size SIZE]
[--opacity OPACITY] [--quality QUALITY]
optional arguments:
-h, --help show this help message and exit
-f FILE, --file FILE image file path or directory
-m MARK, --mark MARK watermark content
-o OUT, --out OUT image output directory, default is ./output
-c COLOR, --color COLOR
text color like '#000000', default is #8B8B1B
-s SPACE, --space SPACE
space between watermarks, default is 75
-a ANGLE, --angle ANGLE
rotate angle of watermarks, default is 30
--font-family FONT_FAMILY
font family of text, default is './font/青鸟华光简琥珀.ttf'
using font in system just by font file name
for example 'PingFang.ttc', which is default installed on macOS
--font-height-crop FONT_HEIGHT_CROP
change watermark font height crop
float will be parsed to factor; int will be parsed to value
default is '1.2', meaning 1.2 times font size
this useful with CJK font, because line height may be higher than size
--size SIZE font size of text, default is 50
--opacity OPACITY opacity of watermarks, default is 0.15
--quality QUALITY quality of output images, default is 90
修改代码支持参数配置
代码上传如下: