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

Python使用Pillow添加水印

 更新時間:2022年05月07日 08:22:17   作者:chenXin@Euler  
這篇文章主要為大家詳細介紹了Python使用Pillow添加水印,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Python使用Pillow添加水印的具體代碼,供大家參考,具體內(nèi)容如下

python數(shù)據(jù)分析得到的圖片,并對照片添加水印pillow
PIL包含在pillow中,所以如果要從PIL導入相關(guān)庫需要安裝pillow

# install?
pip install pillow

安裝完之后就可以下面的頭文件來操作了

from PIL import Image, ImageDraw

采用函數(shù)式編程:

#!/usr/bin/python
from PIL import Image, ImageDraw
from matplotlib import pyplot as plt, font_manager


# 保存通過數(shù)據(jù)分析得到的圖片
def save_img():
?? ?# mac系統(tǒng)下查詢包含中文字體的方式是命令fc-list :lang=zh
?? ?my_font = font_manager.FontProperties(?? ??? ?fname="/System/Library/Assets/com_apple_MobileAsset_Font5/b2d7b382c0fbaa5777103242eb048983c40fb807.asset/AssetData/Kaiti.ttc")

?? ?x = [i for i in range(11, 31)]
?? ?y_1 = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1]
?? ?y_2 = [0, 0, 0, 1, 2, 4, 3, 2, 3, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1]

?? ?# 做出兩個圖,分別包括的是自己和同桌的每個年齡點交的女朋友數(shù)量
?? ?plt.plot(x, y_1, label="自己", color="cyan", linestyle="--")
?? ?plt.plot(x, y_2, label="同桌", color="r")
?? ?
?? ?_xtick_labels = ["{}歲".format(i) for i in x]
?? ?plt.title("每年交的女朋友的數(shù)量走勢圖", fontproperties=my_font)
?? ?# 給x軸添加刻度
?? ?plt.xticks(x, _xtick_labels, fontproperties=my_font, rotation=45)
?? ?# 給y軸添加刻度
?? ?plt.yticks(range(min(y_1), max(y_1) + 1))
?? ?# 給xy軸添加說明
?? ?plt.xlabel("年齡", fontproperties=my_font)
?? ?plt.ylabel("數(shù)量", fontproperties=my_font)

?? ?# 做出網(wǎng)格更加直觀看出坐標點值
?? ?plt.grid(alpha=0.4, linestyle=":")
?? ?# 添加圖例
?? ?plt.legend(prop=my_font)
?? ?plt.savefig("./girl.png")
?? ?plt.show()?


# 對保存的圖片進行添加
def add_watermark(a):
?? ?im = Image.open(a)
?? ?draw = ImageDraw.Draw(im)
?? ?
?? ?# 這里的hello world是添加的水印
?? ?# 數(shù)組(50,50)表示的是水印要添加的位置?
?? ?draw.text((50, 50), 'hello world'.encode('utf-8'), fill=(1, 0, 0)) ?
?? ?im.show()


if __name__ == '__main__':
?? ?save_img()
?? ?add_watermark("girl.png")

代碼輸出的結(jié)果:
注意hello world 就是添加的水印

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論