主頁(yè) > 知識(shí)庫(kù) > Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ絇yinstaller打包exe)

Python實(shí)現(xiàn)圖片指定位置加圖片水印(附Pyinstaller打包exe)

熱門(mén)標(biāo)簽:qt百度地圖標(biāo)注 正安縣地圖標(biāo)注app 電銷(xiāo)機(jī)器人系統(tǒng)廠家鄭州 舉辦過(guò)冬奧會(huì)的城市地圖標(biāo)注 阿里電話機(jī)器人對(duì)話 螳螂科技外呼系統(tǒng)怎么用 遼寧智能外呼系統(tǒng)需要多少錢(qián) 地圖地圖標(biāo)注有嘆號(hào) 400電話申請(qǐng)資格

(一)功能實(shí)現(xiàn)效果:

選擇文件的效果:


標(biāo)記預(yù)加水印的位置:


(二)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"文件夾選擇對(duì)話框")
    b = wx.Button(self, -1, u"請(qǐng)選擇圖片")
    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ī)在水印庫(kù)中挑選一張PNG水印圖片

(三)Python打包成exe程序:

在終端里輸入pyinstaller -F -w add_seal.py

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

(1)出現(xiàn)以下的打包成功信息:



(2)\dist\文件夾出現(xiàn)exe文件:


(3)把exe文件放在主工作區(qū)文件夾,并雙擊運(yùn)行。



(4)成功!

(5)PS:給EXE文件加圖標(biāo)。

1、找一個(gè)ICO格式的圖標(biāo)文件:“redseal.ico”,放在項(xiàng)目文件夾內(nèi)。

2、加redseal.ico,進(jìn)行打包exe。

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

3、移動(dòng)exe的位置,就會(huì)出現(xiàn)圖標(biāo)。

到此這篇關(guān)于Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ剑篜yinstaller打包成exe格式)的文章就介紹到這了,更多相關(guān)Python實(shí)現(xiàn)圖片指定位置加圖片水印(附:Pyinstaller打包成exe格式)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 拒絕盜圖!教你怎么用python給圖片加水印
  • Python如何為圖片添加水印
  • python使用PIL模塊實(shí)現(xiàn)給圖片打水印的方法
  • Python實(shí)現(xiàn)圖片批量加入水印代碼實(shí)例
  • python實(shí)現(xiàn)圖片加文字水印OPenCV和PIL庫(kù)

標(biāo)簽:信陽(yáng) 合肥 濟(jì)源 昭通 阜新 興安盟 淘寶好評(píng)回訪 隨州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python實(shí)現(xiàn)圖片指定位置加圖片水印(附Pyinstaller打包exe)》,本文關(guān)鍵詞  Python,實(shí)現(xiàn),圖片,指定,位置,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ絇yinstaller打包exe)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Python實(shí)現(xiàn)圖片指定位置加圖片水?。ǜ絇yinstaller打包exe)的相關(guān)信息資訊供網(wǎng)民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章