欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

通過Python的filestools庫給圖片添加全圖水印的示例詳解

 更新時(shí)間:2023年04月25日 14:46:08   作者:空空star  
這篇文章主要介紹了通過Python的filestools庫給圖片添加全圖水印,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

前言

大家好,我是空空star,本篇給大家分享一下通過Python的filestools庫給圖片添加全圖水印。

一、filestools庫簡(jiǎn)介

filestools目前包含四個(gè)工具包,分別是樹形目錄顯示、文件差異比較、圖片加水印和curl請(qǐng)求轉(zhuǎn)python代碼。

二、安裝filestools

pip install filestools

三、查看filestools版本

pip show filestools

Name: filestools
Version: 0.1.3
Summary: 仿Linux的tree命令、文件差異比較工具、圖片加水印和curl請(qǐng)求轉(zhuǎn)python代碼。
Home-page: UNKNOWN
Author: 小小明
License: GPLv3
Requires: cchardet, Pillow, pyperclip, rich
Required-by:

四、圖片添加全圖水印

1.引入庫

from watermarker.marker import add_mark

2.添加水印

add_mark(file="demo.jpg",
         out="out",
         mark="空空star",
         color="white",
         size=30,
         opacity=0.3,
         angle=45,
         space=75)

3.效果

五、參數(shù)調(diào)整對(duì)比

1.水印顏色

默認(rèn)#8B8B1B

1.1通過名稱設(shè)置顏色

# 通過RGB值設(shè)置顏色-紅色
color = (255, 0, 0)

1.2通過RGB值設(shè)置顏色

# 通過RGB值設(shè)置顏色-紅色
color = (255, 0, 0)

1.3通過十六進(jìn)制設(shè)置顏色

# 通過十六進(jìn)制設(shè)置顏色-綠色
color = '#6FE000'

2.水印字體的大小

默認(rèn)30

# 左size=30
# 右size=50

3.水印的透明度

默認(rèn)0.15

# 左opacity=0.3
# 右opacity=0.6

4.水印直接的間隔

默認(rèn)75個(gè)空格

# 左space=75
# 右space=100

5.水印旋轉(zhuǎn)角度

默認(rèn)30度

# 左angle=45
# 右angle=-45

總結(jié)

查看marker.py,可以發(fā)現(xiàn),這個(gè)水印處理就是基于PIL庫做的。也能看到水印字體的默認(rèn)值。

從以下代碼中,也可以看到相關(guān)參數(shù)的默認(rèn)值。

def add_mark(file, mark, out="output", color="#8B8B1B", size=30, opacity=0.15, space=75, angle=30):
    if os.path.isdir(file):
        names = os.listdir(file)
        for name in names:
            image_file = os.path.join(file, name)
            add_mark2file(image_file, mark, out, color, size, opacity, space, angle)
    else:
        add_mark2file(file, mark, out, color, size, opacity, space, angle)

到此這篇關(guān)于通過Python的filestools庫給圖片添加全圖水印的文章就介紹到這了,更多相關(guān)Python添加全圖水印內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論