Life is too short , Learn quickly Python!
Copyright is very important , For a picture , Maybe it's your elaborate mind map , Or something you've carefully designed logo. You may spend a lot of time doing , Finally, it was directly carried by others for use , Aerobic oh !
Based on this , In this article, I will take you to learn how to give you Watermark the picture
, Only required 2 That's ok Python Code , Anyone can learn .
What I'm going to introduce to you today is Python library , be called filestools, Developed by Xiao Ming , Use the following command directly , Use... After installation .
pip install filestools --index-url=http://mirrors.aliyun.com/pypi/simple -U
This library integrates 4 Features ,4 All libraries have been migrated to filestools In the library , So install this library , You can use all 4 A function , You just need to use the corresponding function , Import the corresponding modules respectively .
# Watermark the picture
from watermarker.marker import add_mark
add_mark() Methods 8 Parameters , If you don't know how to view parameters , stay jupyter notebook You can enter the following command , You can view it .
Let's talk about add_mark() In the method 8 The meaning of parameters , Introduce the following :
file: Photos to be watermarked ;
mark: What words are used as watermarks ;
out: Location saved after adding watermark ;
color: The color of the watermark font , Default color #8B8B1B;
size: Watermark font size , Default 50;
opacity: Transparency of watermark font , Default 0.15;
space: Interval between watermark Fonts , Default 75 A space ;
angle: Rotation angle of watermark font , Default 30 degree ; Next , We only use one line of code , Add a watermark to the picture .
One line of code to watermark the picture
The original picture looks like this :
When crawling a Chinese Web page , Just two lines of code :
from watermarker.marker import add_mark
add_mark(file=r"aixin.jpg", out=r"C:\Users\Administrator\Desktop\ practice ", mark=" Life is too short , Learn quickly Python", opacity=0.2, angle=45, space=30)
After adding watermark, it looks like this :
Finally, I'll explain to you , The meaning of this line of code .
add_mark(file=r"aixin.jpg",
out=r"C:\Users\Administrator\Desktop\ practice ",
mark=" Life is too short , Learn quickly Python",
opacity=0.2, angle=45, space=30)
meaning : Give the current working environment the name aixin.jpg
Pictures of the , Add a watermark . The watermark is Learn quickly Python
, Watermark transparency is 0.2
, The rotation angle of the watermark is 45°
, The interval between watermarks is 30
A space . After adding watermark , Finally, save the processed image in A specified directory
Next .