
-
语言:简体中文
大小:53M
类别:应用工具
时间:2024-12-02
水印添加工具 V2.0
软件介绍
7.5版本首次更新
在PNG格式的基础上,新增支持jpg、jpeg、bmp格式(你真需要这些格式的水印吗…)。现在,上传的水印图片将在按钮中显示预览图!
选择图片后,还会显示已生成的图片数量和生成路径,并新增了一个小进度条。

代码如下
import osimport sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QFileDialog, QGridLayout, QSizePolicy, QLabel, QProgressBar
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt, QSize
from PIL import Image
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("水印工具2.0")
self.setWindowIcon(QIcon("push.ico"))
self.central_widget = QWidget()
self.setCentralWidget(self.central_widget)
self.layout = QGridLayout(self.central_widget)
self.layout.setSpacing(0)
self.watermark_path = ""
self.image_paths = []
self.output_folder = ""
self.watermark_button = QPushButton("选择水印图片")
self.watermark_button.clicked.connect(self.select_watermark)
self.layout.addWidget(self.watermark_button, 2,0)
self.image_button = QPushButton("选择图片")
self.image_button.clicked.connect(self.select_images)
self.layout.addWidget(self.image_button, 2, 1)
self.folder_label = QLabel()
self.layout.addWidget(self.folder_label, 3, 0)
self.folder_button = QPushButton("选择输出文件夹")
self.folder_button.clicked.connect(self.select_output_folder)
self.layout.addWidget(self.folder_button, 4, 0)
self.start_button = QPushButton("开始添加水印")
self.start_button.clicked.connect(self.start_watermarking)
self.layout.addWidget(self.start_button, 4, 1)
self.progress_bar = QProgressBar()
self.layout.addWidget(self.progress_bar, 5, 0, 1, 2)
self.central_widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.watermark_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.image_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.folder_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.start_button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.central_widget.setLayout(self.layout)
self.setMinimumSize(500, 500)
self.show()
def select_watermark(self):
file_dialog = QFileDialog()
file_dialog.setNameFilter("Image files (*.png *.jpg *.jpeg *.bmp)")
if file_dialog.exec_():
self.watermark_path = file_dialog.selectedFiles()[0]
pixmap = QPixmap(self.watermark_path)
pixmap = pixmap.scaled(self.watermark_button.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
scaled_path = os.path.join(os.path.dirname(self.watermark_path), "scaled_watermark.png")
pixmap.save(scaled_path)
scaled_path = scaled_path.replace('\\', '/') # 替换反斜杠为正斜杠
self.watermark_button.setStyleSheet(f"QPushButton {{background-image: url({scaled_path}); background-position: center; background-repeat: no-repeat; background-attachment: fixed}}")
def select_images(self):
file_dialog = QFileDialog()
file_dialog.setNameFilter("Image files (*.png *.jpg *.jpeg)")
file_dialog.setFileMode(QFileDialog.ExistingFiles)
if file_dialog.exec_():
self.image_paths = file_dialog.selectedFiles()
# 显示选中图片数量
self.image_button.setText(f"选择图片 ({len(self.image_paths)})")
pixmap = QPixmap(self.image_paths[0])
pixmap = pixmap.scaled(self.image_button.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
pixmap.save("scaled_image.png")
self.image_button.setStyleSheet("QPushButton {background-image: url(" + os.path.abspath("scaled_image.png") + "); background-position: center; background-repeat: no-repeat; background-attachment: fixed}")
def select_output_folder(self):
file_dialog = QFileDialog()
file_dialog.setFileMode(QFileDialog.DirectoryOnly)
if file_dialog.exec_():
self.output_folder = file_dialog.selectedFiles()[0]
self.folder_button.setText("输出文件夹: " + self.output_folder)
def start_watermarking(self):
self.progress_bar.setMaximum(len(self.image_paths))
 
展开全部
收起
精品推荐
热门软件
软件排行

TrueCrypt V7.1 汉化版
应用工具 大小:1.6M
下 载

癞蛤蟆工具箱 v4.0.0.7
应用工具 大小:133.71 MB
下 载

SIV-System V4.00绿色版
应用工具 大小:1.3M
下 载

新微软雅黑字体 V6.10 官方版
应用工具 大小:30.6MB
下 载

Magic Bullet Looks V11.5 汉化破解插件
应用工具 大小:275B
下 载

PhotoShop CS3 精简版 50M
应用工具 大小:159.4M
下 载

Nuke9.0 V9 激活版 (含注册机)
应用工具 大小:463M
下 载

技嘉USB驱动注入工具2024 v1.0.0.26
系统工具 大小:21.99M
下 载

爱普生Wicreset V3.80中文版
应用工具 大小:2.37M
下 载

IObit Driver Booster 11 Pro破解版 v11.0.0.21
系统工具 大小:19.88MB
下 载