In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use Python to watermark pictures". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Introduction to filestools Library
Today to introduce you to the Python library, called filestools, developed by Xiao Xiaoming, directly use the following command, use after installation.
Pip install filestools-index-url= http://mirrors.aliyun.com/pypi/simple-U
This library integrates a total of 4 functions, and all 4 libraries have been migrated to the filestools library, so if you install this library, you can use all 4 functions, you just need to use the corresponding functions and import the corresponding modules respectively.
# watermark the image with from watermarker.marker import add_mark
The add_mark () method has a total of eight parameters. If you don't know how to view the parameters, you can enter the following command in jupyter notebook to view them.
The following is to show you the meaning of the eight parameters in the add_mark () method, as follows:
File: the photo to be watermarked
Mark: which words are used as watermarks
Out: where to save after adding the watermark
Color: color of the watermark font. Default color # 8B8B1B
Size: font size of the watermark. Default is 50.
Opacity: transparency of watermark fonts. Default is 0.15.
Space: the interval between watermark fonts. Default is 75 spaces.
Angle: the rotation angle of the watermark font, which defaults to 30 degrees. Next, we will add a watermark to the image with only one line of code.
One line of code to watermark the picture
The original picture looks like this:
Use the following line of code, just two lines of code:
From watermarker.marker import add_markadd_mark (file=r "aixin.jpg", out=r "C:\ Users\ Administrator\ Desktop\ practice", mark= "Life is too short, learn Python", opacity=0.2, angle=45, space=30)
The watermark looks like this:
Finally, I would like to 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 Python", opacity=0.2, angle=45, space=30)
Meaning: add a watermark to the picture named aixin.jpg in the current working environment. The watermark word is Quick Learning Python, the transparency of the watermark is 0.2, the rotation angle of the watermark is 45 °, and the interval between the watermarks is 30 spaces. After adding the watermark, finally save the processed image in a specified directory.
"how to use Python to achieve the effect of watermarking pictures," the content is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.