# Time: 2020/06/04
#Author: Xiaohong
# 运行环境: OS: Windows 10
# Python: 3.7
# 功能: 给照片加入水印
主界面:
主程序(Tl_c01.py):
import sys
import time
import os
from PyQt5.QtWidgets import *
from PyQt5 import QtGui, QtCore, QtWidgets
# from PyQt5.QtWidgets import QTableWidget, QProgressBar, QLineEdit, QComboBox, QFrame, QTableWidgetItem
from PyQt5.QtCore import *
from PyQt5.QtGui import *
# 这个test_pyqt是ui文件对应的py文件的文件名
from Ui_qt_C01 import Ui_qtC01
from PIL import Image, ImageDraw, ImageFont #pip3 install pillow
# 调用 QT 设计的界面对应的类
# 指定要使用的字体和大小
font = ImageFont.truetype("C:/Windows/Fonts/STFANGSO.TTF", 24)
class WC01(QDialog):
def __init__(self, parent=None):
super(WC01, self).__init__(parent)
self.child = Ui_qtC01()
self.child.setupUi(self)
self.child.btn_select_file.clicked.connect(self.select_file)
# self.child.btn_show_pic.clicked.connect(self.show_pic_orig)
self.child.btn_Watermark.clicked.connect(self.add_watermark)
# 设立函数,来取得当前时间
def get_sysdate(self):
now = time.strftime("%Y%m%d %H%M%S", time.localtime(time.time()))
# print(now)
return now
def select_file(self):
fileName, filetype = QFileDialog.getOpenFileName(
self, "选择文件", "/", "All Files (*);;jpg Files (*.jpg)") # User 选择路径来找到图片文件
# print(fileName, filetype) # 打印文件全部路径(包括文件名和后缀名)和文件类型
self.child.t_file.setText(fileName) # 把文件的路径写在 Text 上
self.show_pic_orig()
def show_pic_orig(self):
filename2 = self.child.t_file.text()
if filename2 == '':
pass
else:
self.child.lbl_pic_orig.setPixmap(
QPixmap(filename2)) # 在label上显示图片
self.child.lbl_pic_orig.setScaledContents(True) # 让图片自适应label大小
# image: 图片 text:要添