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

The method of adding text / image watermarks to images in Python is particularly simple and easy to use. Filestools and PIL modules

編輯:Python

pip install filestools -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

from watermarker.marker import add_mark
import os
import cv2
import winreg
def read_directory(directory_name, b):
# this loop is for read each image in this foder,directory_name is the foder name with images.
for filename in os.listdir(directory_name):
print(filename)
add_mark(file=directory_name + '\\' + str(filename), out=get_desktop() + '\ Watermarked ',
mark=b, opacity=0.2, angle=30, space=30)
def get_desktop():
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
return winreg.QueryValueEx(key, "Desktop")[0]
if __name__ == '__main__':
a = input(' Enter full picture folder path :')
b = input(' Watermark text :')
read_directory(a, b)

About add_mark() function , They are as follows 8 Parameters :
file: Original photos ;
mark: What characters 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 ;
 


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