程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python teaches you two lines of code to add watermarks, which is super simple~

編輯:Python

Preface

Good morning, everyone 、 Good afternoon 、 Good evening ~

Today I will share one python How to add watermark ~ After learning, you don't have to add watermarks by yourself ,

Just click to run ~ python It's done for you by itself ! Only required 2 That's ok Python Code , Anyone can learn .

Catalog ( You can click on the place you want to see )

  • Preface
  • Get ready
    • Environment use :
      • How to configure pycharm Inside python Interpreter ?
      • pycharm How to install plug-ins ?
    • Module USES :
      • install python Third-party module :
  • Code
    • One 、 Add a watermark to a single picture
    • Two 、 Batch add multiple image watermarks
  • Tail language


This article Article code provider : Qingdeng Education - Self Travel


Get ready

First, let's prepare something , Help us run the code better

Environment use :

  • Python 3.8

  • Pycharm

How to configure pycharm Inside python Interpreter ?

  1. choice file( file ) >>> setting( Set up ) >>> Project( project ) >>> python interpreter(python Interpreter )

  2. Click on the gear , choice add

  3. add to python The installation path

pycharm How to install plug-ins ?

  1. choice file( file ) >>> setting( Set up ) >>> Plugins( plug-in unit )

  2. Click on Marketplace Enter the name of the plug-in you want to install such as : Translation plug-ins Input translation / Chinese plug-in Input Chinese

  3. Select the corresponding plug-in and click install( install ) that will do

  4. After successful installation Yes, it will pop up restart pycharm The option to Click ok , Restart to take effect


Insinuation of insinuation , Ha ha ha ha ha ha ha

Module USES :

  • filestools ( Third-party module , Need to install )

install python Third-party module :

  • win + R Input cmd Click ok , Enter the installation command pip install Module name (pip install requests) enter
  • stay pycharm Click on the Terminal( terminal ) Enter the installation command

The installation and download speed is too slow , Or wrong , You can switch the image source installation ~

Code

One 、 Add a watermark to a single picture

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() 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 .

  • 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 .

add_mark('C:\\Users\\ Qingdeng Education \\Desktop\\111\\1.jpg', mark=' give the thumbs-up 、 Focus on 、 Collect ', opacity=0.5)

The link here is a link to a single image ~

You can click on image properties —> Security —> See the object name

good , So let's run this , Look at our results

Original picture :

design sketch :

Two 、 Batch add multiple image watermarks

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('C:\\Users\\ Qingdeng Education \\Desktop\\111')
for file in files:
add_mark('C:\\Users\\ Qingdeng Education \\Desktop\\111\\'+file, mark=' give the thumbs-up 、 Focus on 、 Collect ', opacity=0.5)


Need source code and Python I can get the information for free ~

We can study more details by ourselves ~

Yes , The following folder ( That is, the file generated for you after running the code ) If you want to run it again, please delete it , Otherwise, it will be wrong

Tail language

Okay , My article ends here !

There are more suggestions or questions to comment on or send me a private letter ! Come on together and work hard (ง •_•)ง

If you like, just pay attention to the blogger , Or like the collection and comment on my article !!!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved