吾爱软件园 电脑软件 应用软件 免费加水印小软件 V2.0
免费加水印小软件 V2.0 免费加水印小软件 V2.0

免费加水印小软件 V2.0

  • 类别:应用软件
  • 大小:53M
  • 更新:2023-07-08 00:00:00
  • 下载:393次
软件简介

7.5第一次更新

在PNG基础上追加jpg,jpeg,bmp格式(真的需要其他格式的水印吗...)
现在上传完的水印图片会在按钮内显示水印的预览图啦!
现在选择完图片也会显示生成了多少张图片和生成的路径,并且添加了一个小进度条
免费加水印小软件

以下是代码

import os
import 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))
 
        for index, image_path in enumerate(self.image_paths):
            image = Image.open(image_path)
            watermark = Image.open(self.watermark_path)
            watermark = watermark.resize(image.size, Image.ANTIALIAS)
            image.paste(watermark, (0,0), watermark)
            image.save(os.path.join(self.output_folder, os.path.basename(image_path)))
            self.progress_bar.setValue(index + 1)
 
if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    app.setWindowIcon(QIcon("ppush.ico"))  # 设置应用程序的图标,将显示在任务栏
    sys.exit(app.exec_())
软件截图
标题:免费加水印小软件 V2.0
链接:http://www.52zixue.com/pc/yy/25791.html
版权:文章转载自网络,如有侵权,请联系删除!
资讯推荐
更多
iOS14.5反追踪用户隐私功能有什么用

iOS14.5反追踪用户隐私功能有什么用?对于很多苹果用户来说,一些功能是默认开启,但是很多用户都不知道有什么用

2023-07-08
小米mix fold有前置摄像头吗

小米mix fold有前置摄像头吗?作为小米的第一款折叠屏手机,这款手机可以说实话非常的强大,但是很多网友还是想要

2023-07-08
小米11青春版有dc调光吗

小米11青春版有dc调光吗?对于很多网友来说熬夜耍手机已经是常态了但是手机的光线对于用户来说又非常的伤眼睛

2023-07-08
做超声检查时,医生为什么要在患者肚子上涂粘粘的东西

做B超为什么要涂凝胶?在支付宝蚂蚁庄园每日一题中,2021年4月9日的问题是问做超声检查时,医生为什么要在患者肚

2023-07-08
蚂蚁庄园4月9日答案最新

蚂蚁庄园2021年4月9日答案最新版是什么?在支付宝蚂蚁庄园每日一题中,2021年4月9日的问题有超声检查为什么要涂

2023-07-08
最佳密码管理工具——Windows版

密码是你抵御网络威胁的最后一道防线。只要回顾一下最近的一些数据泄露和网络攻击,包括大众关注的OPM(美国联

2023-07-08