# -*l- coding:utf-8 *
import os, io, sys, re, time, json
from pandas import array
import matplotlib.backends.backend_tkagg
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
#from matplotlib.pyplot import imshow, ginput
from PIL import Image, ImageEnhance, ImageFilter
import wx
import numpy as np
import random
class DirDialog(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, -1, u"文件夾選擇對話框")
b = wx.Button(self, -1, u"請選擇圖片")
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, event):
# file_wildcard = "Paint files(*.paint)|*.paint|All files(*.*)|*.*"
dlg = wx.FileDialog(self, u"選擇文件夾", style=wx.DD_DEFAULT_STYLE)
if dlg.ShowModal() == wx.ID_OK:
jpegname = dlg.GetPath() # 文件夾路徑
print(jpegname)
np.savez('dir.npz', k_a=str(jpegname))
dlg.Destroy()
def sealmark(img_seal, img_new):
try:
data_a = np.load('dir.npz')#保存地址數(shù)據(jù)
img_source = str(data_a['k_a']) # 原圖片的地址
im1 = Image.open(img_source)
plt.imshow(im1)
xy = plt.ginput(1)
xo = xy[0][0]
yo = xy[0][1]
ks = im1.size[1] * 0.000478
wm = Image.open(img_seal)
wm = wm.resize((int(wm.width * ks), int(wm.height * ks))) # wm.with * k=280 * ks
layer = Image.new('RGBA', im1.size, (0, 0, 0, 0))
layer.paste(wm, (int(xo), int(yo)))
newIm = Image.composite(layer, im1, layer)
newIm.save(img_new)
print(img_seal)
except Exception as e:
print(">>>>>>>>>>> sealMark EXCEPTION: " + str(e))
return False
else:
return True
if __name__ == '__main__':
frame = wx.App()
app = DirDialog()
app.Show()
frame.MainLoop()
sealmark("水印\水印" + str(random.randrange(10)) + ".png", "after_seal.jpg") #random.randrange(10):隨機(jī)在水印庫中挑選一張PNG水印圖片
到此這篇關(guān)于Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ剑篜yinstaller打包成exe格式)的文章就介紹到這了,更多相關(guān)Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ剑篜yinstaller打包成exe格式)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!