神剑山庄资源网 Design By www.hcban.com

(一)功能实现效果:

选择文件的效果:

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

标记预加水印的位置:

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

(二)Python代码:

# -*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')#保存地址数据
    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):随机在水印库中挑选一张PNG水印图片

(三)Python打包成exe程序:

在终端里输入pyinstaller -F -w add_seal.py

C:\Users\Administrator\Desktop\seal>pyinstaller -F -w add_seal.py

(1)出现以下的打包成功信息:

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

(2)\dist\文件夹出现exe文件:

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

(3)把exe文件放在主工作区文件夹,并双击运行。

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

(4)成功!

(5)PS:给EXE文件加图标。

1、找一个ICO格式的图标文件:“redseal.ico”,放在项目文件夹内。

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

2、加redseal.ico,进行打包exe。

pyinstaller -F -w -i redseal.ico add_seal.py

3、移动exe的位置,就会出现图标。

Python实现图片指定位置加图片水印(附Pyinstaller打包exe)

标签:
Python,图片指定位置加水印,Python,图片水印

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“Python实现图片指定位置加图片水印(附Pyinstaller打包exe)”

暂无Python实现图片指定位置加图片水印(附Pyinstaller打包exe)的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。