A super simple case , The one with hands ~
We usually add watermark to the picture , But not PS, I have to ask my friends for help , however , This time you find friends , Next time your sister , Xuemei , Female student , Female colleagues need your help , Are you still looking for friends ?
What a shame , You can't learn by yourself ~
And if there are many pictures ,PS It's still quite slow , use Python One click generation , Efficiency bars .
The environment I use here is Python and pycharm
If you add a watermark to an image , Just two lines of code .
The module used this time is filestools , Third-party module , We need to install it manually .
win+r Open the search box , Input cmd Press OK to pop up the command prompt window , Input pip install filestools You can install it successfully .
The installation and download speed is too slow , Or wrong , You can see the top article on my homepage , The content in this aspect was explained in detail .
Module import
How do you use it? filestools Module? ?
First, import a method in the module ,watermarker , light marker , then import add_mark
from watermarker.marker import add_mark
add_mark Many methods have been included
file Yes add watermark photo ,mark What words are used as watermarks ,out Place of preservation ,color Color ,size Watermark font size ,opacity The opacity ,space Font spacing ,angle Rotation Angle .
Try any picture
Now I want to add : Life is too short , Learn quickly python
Let's add pictures and words
from watermarker.marker import add_mark
add_mark('img.png, mark=' Life is too short , Learn quickly python')
You can see the effect
Just look for a picture without watermark , I'll show you my little sister's picture .
If you add pictures in batches , Need to use OS modular .
Import it
from watermarker.marker import add_mark
import os
use os The module reads all the contents of the folder , Use files receive .
files = os.listdir('img_1\\')
A print
from watermarker.marker import add_mark
import os
files = os.listdir('img_1\\')
print(files)
effect
Now all the file names are
adopt for Loop traversal is printed out
for file in files:
Then add the file , What we read is img_1\ What's in it , Then transfer all the contents of this file , When saving data , Will be kept here .
from watermarker.marker import add_mark
import os
files = os.listdir('img_1\\')
print(files)
for file in files:
add_mark(f'img_1\\{
file}', mark=' Life is too short , Learn quickly python')
I won't open them one by one
Change the transparency again
It is the default 0.15, I'll change it here to 0.5 try
from watermarker.marker import add_mark
import os
files = os.listdir('img_1\\')
print(files)
for file in files:
add_mark(f'img_1\\{
file}', mark=' Life is too short , Learn quickly python', opacity=0.5)
So it's much clearer ~
Need source code and Python Click the business card below for information
That's all for sharing today , Follow me to learn more interesting and useful Python Tips !