Watermark the picture with Python

The way of Python data 2022-05-14 13:46:11 阅读数:568

watermarkpicturepython

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 .

filestools Library Introduction

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 .

a38e9820f6e123aaa76ae379ec7c110b.png

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 :

462d4b6a991b289bb76d112b3326be2b.png

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 :

bd65fbd75ff3a1d24e8010cacba7f105.png

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 .

If you want to study in detail filestools library , Refer to the website below :

https://pypi.org/project/filestools/

-------- End --------

b6cb860969135f143f87342bb30967ed.png

54128ca57711859e0217256b5337653e.png

版权声明:本文为[The way of Python data]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/134/202205141328317900.html