Just one line of Python code to copyright an image!

WBOY
Release: 2023-04-14 19:07:01
forward
1261 people have browsed it

Today a friend complained to me: Some time ago, I worked hard to compile a XX guide and shared it with some of my friends. As a result, today I saw someone openly using the picture of this guide to attract traffic, claiming that it was It makes no sense to organize it yourself!

He himself concluded that every step of the way gained wisdom, and asked me if there was any simple way to add watermarks to pictures.

As a senior technical person, of course the answer is: Yes!

If you search online, you will definitely find many ways to add watermarks.

Today I will introduce to you how to add watermark to pictures with one line of code!

Installation Tools

The Python library introduced to you today is called filestools. Use the following command directly and use it after installation. filestools has many functions. Today we will learn how to add watermarks to images.

pip install filestools -U
Copy after login

You can also use Alibaba Cloud to accelerate:

pip install filestools --index-url=http://mirrors.aliyun.com/pypi/simple -U
Copy after login

Of course, if you want to download the latest version, you can use the following command:

pip install filestools --index-url https://pypi.org/simple/ -U
Copy after login

Add watermark to picture

This should be the best image watermarking code I have ever seen. The add_mark function is called to add watermarks to images.

About the add_mark function, there are the following 8 parameters:

file: the photo to be added with watermark; mark: which words to use as watermark; out: the location where the watermark is saved after adding the watermark; color: watermark Font color, default color #8B8B1B; size: watermark font size, default 50; opacity: watermark font transparency, default 0.15; space: interval between watermark fonts, default 75 spaces; angle: rotation angle of watermark font , the default is 30 degrees.

Below we randomly find a picture as an example:

Just one line of Python code to copyright an image!

Our code is as follows:

from watermarker.marker import add_mark
add_mark(file=r"./test/testmarker.jpg", out=r"./output", mark="闲欢", opacity=0.5, angle=30, space=30, size=100)
Copy after login

After running the code, it will be Generate a picture in the output directory:

Just one line of Python code to copyright an image!

We can see that the watermark of the word "Xianhuan" has been added to the generated picture.

Is this watermark effect the same as that of some PDF documents?

You can adjust the parameters yourself to achieve the best results.

Summary

Python’s third-party open source library is really powerful and can satisfy all kinds of functions. We just need to make good use of it and we can stand on the shoulders of giants. Achieve a variety of needs!

The above is the detailed content of Just one line of Python code to copyright an image!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template