When working, especially self-media workers, watermark adding tools are necessary to protect intellectual property images. There are many online/downloaded watermark adding tools on the Internet, but they may There are at least one of the following problems:
1. Online tools need to upload pictures to the other party's server, and the information is not secure.
2. Many tools do not have batch processing capabilities.
3. Many tools have too few customizable functions, such as watermark transparency, fonts, etc.
4. The operation is cumbersome.
Now as long as you know how to use commands, we can teach you how to use Python to add watermarks to pictures super easily, and it has the following features:
1. Supports custom watermark fonts.
2. Support custom text content and color.
3. Support batch processing.
4. Support setting the space between watermarks.
5. Support setting watermark font size.
6. Support setting transparency.
7. Your own code, safe.
We need to use the 2Dou open source project:
https://www.php.cn/link/4b5b81483048c8942ed00caaa17b9535
Very useful open source project, thanks to the original author.
There are three ways to download this project:
1. If your network can access github, you can enter the page, click clone or download and then click Download Zip.
2. If you have downloaded git, you can use cmd/terminal to enter the folder where you want to place it, and enter the command:
git clone https://www.php.cn/link/4b5b81483048c8942ed00caaa17b9535.git
3. If you don’t have one, you can directly reply to the watermark in the background of the Python Practical Collection official account Download the complete code for the repaired version of this article.
Download and unzip it to any folder you want to place it. It is best not to include Chinese names in the path. If you downloaded using the first two methods and are a Windows system user, be careful to change the font file name of the project to English. In addition, there is also a place in marker.py that needs to be changed. As follows:
Change the Blue Bird Huaguang Jane Amber.ttf in the font folder to bird.ttf. It doesn’t matter what the name is. The key point is not to use a Chinese name, otherwise pillow The modified file will not be available.
Note that the tenth line in the marker.py file should be changed to the corresponding name, corresponding to the font file name in the font folder.
We just mentioned the pillow library. The operation of this package requires the use of this third-party library, which is specially used to process images. Open CMD/Terminal and enter the following command to install:
pip install pillow
After the installation is complete, we can try it! The most common example is as follows. Place the pictures you need to watermark in the input folder of the project, then enter the folder where you store the project in cmd/Terminal and enter the following commands:
python marker.py -f ./input/baby.jpg -m python实用宝典
each The meaning of the parameters is as follows:
-f File path: It is the path of your picture
-m Text content: It is the content of the watermark you want to make
The parameters are not The setting is the default value. After the operation is completed, the corresponding watermarked picture will appear in the output folder. The effect is as follows:
Add watermark
The default watermark color is...shit yellow picture?
But it doesn’t matter, we can modify its color and add the -c parameter! (The default format of the parameter is # followed by 6 hexadecimal digits). Using the image tool, we can find the value of your favorite color:
Then we enter the command:
python marker.py -f ./input/baby.jpg -m python实用宝典 -c #232862
Success ! Take a look at the effect:
#Modify the watermark color
Yeah! It looks better, but it seems that the color of the watermark is a bit dark. We can modify the transparency to make it lighter. The default transparency is 0.15, which can make this value smaller. Set the opacity parameter:
python marker.py -f ./input/baby.jpg -m python实用宝典 -c #232862 --opacity 0.08
The result is as follows:
The watermark becomes more transparent
In fact, there are other parameters, we will not show them one by one, there are these parameters in total:
- -f 参数,指定打水印的文件,如果你想打印整个文件夹,则输入该文件夹路径即可。
- -m 参数,指定水印内容。
- -o 参数,指定输出水印文件的位置,默认为output文件夹。
- -c 参数,指定水印的颜色,默认值为shi..啊不,黄色,#8B8B1B.
- -s 参数,指定水印与水印之间的空隙,默认值为75.
- -a 参数,指定水印的旋转角度,我们的例子中都是默认值30度。
- --size参数,指定水印文本字体大小,默认值为50。
- --opacity参数,指定透明度,默认为0.15,数值越小越透明。
接下来给大家试试批量处理功能,首先把所有图片放置到项目的input文件夹下:
然后输入命令里,指定文件夹即可!
python marker.py -f ./input -m python实用宝典 -c #232862 --o
你会看到input文件夹名后没有/baby.jpg了,这表明将input文件夹下所有的图片打水印。
看到 文件名 succes 则说明批处理成功!
还有一个隐藏功能!如果你想要修改字体也可以哦!还记得我们前面怎么修复windows的中文名问题吗?如图,你只要将新的字体文件放到font文件夹下,然后修改TTF_FONT变量里的字体名字,与font文件夹下的新字体名字相对应即可改成你想要的字体了图片!
修改字体
我们的文章到此就结束啦,如果你希望我们今天的Python教程,请持续关注我们,如果对你有帮助,麻烦在下面点一个赞/在看哦图片有任何问题都可以在下方留言区留言,我们都会耐心解答的!
The above is the detailed content of Python batch watermarking only requires one line of commands!. For more information, please follow other related articles on the PHP Chinese website!

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version