- 功能
分辨率的批量转换,文件夹递归查找
像素偏移量批量调整,文件夹单层查找
画布的大小的批量进行调整,不进行缩放,文件夹单层查找
- 界面
- 通过PyUIC生成的代码
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'E:\Development\IProcesser/IProcessingDialog.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(411, 525)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.tabWidget = QtWidgets.QTabWidget(Dialog)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.verticalLayout = QtWidgets.QVBoxLayout(self.tab)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.label_5 = QtWidgets.QLabel(self.tab)
self.label_5.setObjectName("label_5")
self.horizontalLayout_5.addWidget(self.label_5)
self.reslotion_src_le = QtWidgets.QLineEdit(self.tab)
self.reslotion_src_le.setObjectName("reslotion_src_le")
self.horizontalLayout_5.addWidget(self.reslotion_src_le)
self.reslotion_src_view_btn = QtWidgets.QPushButton(self.tab)
self.reslotion_src_view_btn.setObjectName("reslotion_src_view_btn")
self.horizontalLayout_5.addWidget(self.reslotion_src_view_btn)
self.verticalLayout.addLayout(self.horizontalLayout_5)
self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.label_8 = QtWidgets.QLabel(self.tab)
self.label_8.setObjectName("label_8")
self.horizontalLayout_7.addWidget(self.label_8)
self.reslotion_dst_le = QtWidgets.QLineEdit(self.tab)
self.reslotion_dst_le.setEnabled(True)
self.reslotion_dst_le.setObjectName("reslotion_dst_le")
self.horizontalLayout_7.addWidget(self.reslotion_dst_le)
self.reslotion_dst_view_btn = QtWidgets.QPushButton(self.tab)
self.reslotion_dst_view_btn.setObjectName("reslotion_dst_view_btn")
self.horizontalLayout_7.addWidget(self.reslotion_dst_view_btn)
self.verticalLayout.addLayout(self.horizontalLayout_7)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label_6 = QtWidgets.QLabel(self.tab)
self.label_6.setObjectName("label_6")
self.horizontalLayout.addWidget(self.label_6)
self.reslotion_srcw_le = QtWidgets.QLineEdit(self.tab)
self.reslotion_srcw_le.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.reslotion_srcw_le.setObjectName("reslotion_srcw_le")
self.horizontalLayout.addWidget(self.reslotion_srcw_le)
self.label_7 = QtWidgets.QLabel(self.tab)
self.label_7.setObjectName("label_7")
self.horizontalLayout.addWidget(self.label_7)
self.reslotion_srch_le = QtWidgets.QLineEdit(self.tab)
self.reslotion_srch_le.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.reslotion_srch_le.setObjectName("reslotion_srch_le")
self.horizontalLayout.addWidget(self.reslotion_srch_le)
self.label_10 = QtWidgets.QLabel(self.tab)
self.label_10.setObjectName("label_10")
self.horizontalLayout.addWidget(self.label_10)
self.reslotion_dstw_le = QtWidgets.QLineEdit(self.tab)
self.reslotion_dstw_le.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.reslotion_dstw_le.setObjectName("reslotion_dstw_le")
self.horizontalLayout.addWidget(self.reslotion_dstw_le)
self.label_9 = QtWidgets.QLabel(self.tab)
self.label_9.setObjectName("label_9")
self.horizontalLayout.addWidget(self.label_9)
self.reslotion_dsth_le = QtWidgets.QLineEdit(self.tab)
self.reslotion_dsth_le.setInputMethodHints(QtCore.Qt.ImhDigitsOnly)
self.reslotion_dsth_le.setObjectName("reslotion_dsth_le")
self.horizontalLayout.addWidget(self.reslotion_dsth_le)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_8.addItem(spacerItem)
self.reslotion_submit_btn = QtWidgets.QPushButton(self.tab)
self.reslotion_submit_btn.setEnabled(True)
self.reslotion_submit_btn.setObjectName("reslotion_submit_btn")
self.horizontalLayout_8.addWidget(self.reslotion_submit_btn)
self.verticalLayout.addLayout(self.horizontalLayout_8)
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.tab_2)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label = QtWidgets.QLabel(self.tab_2)
self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.label)
self.offset_pixel_le = QtWidgets.QLineEdit(self.tab_2)
self.offset_pixel_le.setObjectName("offset_pixel_le")
self.horizontalLayout_2.addWidget(self.offset_pixel_le)
self.label_2 = QtWidgets.QLabel(self.tab_2)
self.label_2.setObjectName("label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.offset_meter_le = QtWidgets.QLineEdit(self.tab_2)
self.offset_meter_le.setObjectName("offset_meter_le")
self.horizontalLayout_2.addWidget(self.offset_meter_le)
self.label_3 = QtWidgets.QLabel(self.tab_2)
self.label_3.setObjectName("label_3")
self.horizontalLayout_2.addWidget(self.label_3)
self.verticalLayout_4.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.label_4 = QtWidgets.QLabel(self.tab_2)
self.label_4.setObjectName("label_4")
self.horizontalLayout_3.addWidget(self.label_4)
self.offset_dire_le = QtWidgets.QLineEdit(self.tab_2)
self.offset_dire_le.setObjectName("offset_dire_le")
self.horizontalLayout_3.addWidget(self.offset_dire_le)
self.offset_view_btn = QtWidgets.QPushButton(self.tab_2)
self.offset_view_btn.setObjectName("offset_view_btn")
self.horizontalLayout_3.addWidget(self.offset_view_btn)
self.verticalLayout_4.addLayout(self.horizontalLayout_3)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.label_11 = QtWidgets.QLabel(self.tab_2)
self.label_11.setObjectName("label_11")
self.horizontalLayout_4.addWidget(self.label_11)
self.offset_ltx_le = QtWidgets.QLineEdit(self.tab_2)
self.offset_ltx_le.setMaximumSize(QtCore.QSize(50, 16777215))
self.offset_ltx_le.setObjectName("offset_ltx_le")
self.horizontalLayout_4.addWidget(self.offset_ltx_le)
self.label_12 = QtWidgets.QLabel(self.tab_2)
self.label_12.setObjectName("label_12")
self.horizontalLayout_4.addWidget(self.label_12)
self.offset_lty_le = QtWidgets.QLineEdit(self.tab_2)
self.offset_lty_le.setMaximumSize(QtCore.QSize(50, 16777215))
self.offset_lty_le.setObjectName("offset_lty_le")
self.horizontalLayout_4.addWidget(self.offset_lty_le)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem1)
self.rename_ckb = QtWidgets.QCheckBox(self.tab_2)
self.rename_ckb.setObjectName("rename_ckb")
self.horizontalLayout_4.addWidget(self.rename_ckb)
self.verticalLayout_4.addLayout(self.horizontalLayout_4)
self.horizontalLayout_6 = QtWidgets.QHBoxLayout()
self.horizontalLayout_6.setObjectName("horizontalLayout_6")
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_6.addItem(spacerItem2)
self.offset_submit_btn = QtWidgets.QPushButton(self.tab_2)
self.offset_submit_btn.setObjectName("offset_submit_btn")
self.horizontalLayout_6.addWidget(self.offset_submit_btn)
self.verticalLayout_4.addLayout(self.horizontalLayout_6)
self.tabWidget.addTab(self.tab_2, "")
self.tab_5 = QtWidgets.QWidget()
self.tab_5.setObjectName("tab_5")
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.tab_5)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_9 = QtWidgets.QHBoxLayout()
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
self.label_13 = QtWidgets.QLabel(self.tab_5)
self.label_13.setObjectName("label_13")
self.horizontalLayout_9.addWidget(self.label_13)
self.size_directory_le = QtWidgets.QLineEdit(self.tab_5)
self.size_directory_le.setObjectName("size_directory_le")
self.horizontalLayout_9.addWidget(self.size_directory_le)
self.size_view_btn = QtWidgets.QPushButton(self.tab_5)
self.size_view_btn.setObjectName("size_view_btn")
self.horizontalLayout_9.addWidget(self.size_view_btn)
self.verticalLayout_5.addLayout(self.horizontalLayout_9)
self.horizontalLayout_10 = QtWidgets.QHBoxLayout()
self.horizontalLayout_10.setObjectName("horizontalLayout_10")
self.label_14 = QtWidgets.QLabel(self.tab_5)
self.label_14.setObjectName("label_14")
self.horizontalLayout_10.addWidget(self.label_14)
self.size_width_le = QtWidgets.QLineEdit(self.tab_5)
self.size_width_le.setInputMethodHints(QtCore.Qt.ImhNone)
self.size_width_le.setObjectName("size_width_le")
self.horizontalLayout_10.addWidget(self.size_width_le)
self.label_15 = QtWidgets.QLabel(self.tab_5)
self.label_15.setObjectName("label_15")
self.horizontalLayout_10.addWidget(self.label_15)
self.size_height_le = QtWidgets.QLineEdit(self.tab_5)
self.size_height_le.setInputMethodHints(QtCore.Qt.ImhNone)
self.size_height_le.setObjectName("size_height_le")
self.horizontalLayout_10.addWidget(self.size_height_le)
self.verticalLayout_5.addLayout(self.horizontalLayout_10)
spacerItem3 = QtWidgets.QSpacerItem(20, 41, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_5.addItem(spacerItem3)
self.horizontalLayout_11 = QtWidgets.QHBoxLayout()
self.horizontalLayout_11.setObjectName("horizontalLayout_11")
spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_11.addItem(spacerItem4)
self.size_submit_btn = QtWidgets.QPushButton(self.tab_5)
self.size_submit_btn.setObjectName("size_submit_btn")
self.horizontalLayout_11.addWidget(self.size_submit_btn)
self.verticalLayout_5.addLayout(self.horizontalLayout_11)
self.tabWidget.addTab(self.tab_5, "")
self.verticalLayout_2.addWidget(self.tabWidget)
self.groupBox_3 = QtWidgets.QGroupBox(Dialog)
self.groupBox_3.setObjectName("groupBox_3")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.groupBox_3)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.output_lw = QtWidgets.QListWidget(self.groupBox_3)
self.output_lw.setObjectName("output_lw")
self.verticalLayout_3.addWidget(self.output_lw)
self.verticalLayout_2.addWidget(self.groupBox_3)
self.verticalLayout_2.setStretch(1, 2) self.retranslateUi(Dialog)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "IProcesser"))
self.label_5.setText(_translate("Dialog", "Src:"))
self.reslotion_src_view_btn.setText(_translate("Dialog", "View..."))
self.label_8.setText(_translate("Dialog", "Dst:"))
self.reslotion_dst_view_btn.setText(_translate("Dialog", "View..."))
self.label_6.setText(_translate("Dialog", "SrcW"))
self.label_7.setText(_translate("Dialog", "SrcH"))
self.label_10.setText(_translate("Dialog", "DstW:"))
self.label_9.setText(_translate("Dialog", "DstH:"))
self.reslotion_submit_btn.setText(_translate("Dialog", "Submit"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Dialog", "分辨率转换"))
self.label.setText(_translate("Dialog", "设定像素比:"))
self.offset_pixel_le.setPlaceholderText(_translate("Dialog", ""))
self.label_2.setText(_translate("Dialog", "Pixel"))
self.offset_meter_le.setPlaceholderText(_translate("Dialog", ""))
self.label_3.setText(_translate("Dialog", "Meter"))
self.label_4.setText(_translate("Dialog", "序列文件夹:"))
self.offset_view_btn.setText(_translate("Dialog", "View..."))
self.label_11.setText(_translate("Dialog", "LTx:"))
self.offset_ltx_le.setPlaceholderText(_translate("Dialog", ""))
self.label_12.setText(_translate("Dialog", "LTy:"))
self.offset_lty_le.setPlaceholderText(_translate("Dialog", ""))
self.rename_ckb.setText(_translate("Dialog", "改名"))
self.offset_submit_btn.setText(_translate("Dialog", "Submit"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Dialog", "偏移值调整"))
self.label_13.setText(_translate("Dialog", "目录:"))
self.size_view_btn.setText(_translate("Dialog", "View..."))
self.label_14.setText(_translate("Dialog", "设定宽度:"))
self.label_15.setText(_translate("Dialog", "设定高度:"))
self.size_submit_btn.setText(_translate("Dialog", "Submit"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_5), _translate("Dialog", "尺寸调整"))
self.groupBox_3.setTitle(_translate("Dialog", "输出")) import IProcessing_rc
- Wrap PyUIC生成的代码
# coding=utf-8
import os, shutil, threading, math
from PIL import Image
from PyQt5.QtCore import *
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import * import IProcessingDialog
import IProcessing_rc class IPDW(QDialog, IProcessingDialog.Ui_Dialog):
output_lw_signal = pyqtSignal(str)
reslotion_submit_signal = pyqtSignal() def __init__(self):
super(IPDW, self).__init__()
self.setupUi(self)
# icon
self.setWindowIcon(QIcon(':/icon/icon.ico'))
# 信号连接
self.output_lw_signal.connect(self.output_lw_signal_proc)
# 分辨率调整
self.reslotion_src_view_btn.clicked.connect(self.reslotion_src_view_btn_clicked)
self.reslotion_dst_view_btn.clicked.connect(self.reslotion_dst_view_btn_clicked)
self.reslotion_submit_btn.clicked.connect(self.reslotion_submit_btn_clicked)
# 偏移调整
self.offset_view_btn.clicked.connect(self.offset_view_btn_clicked)
self.offset_submit_btn.clicked.connect(self.offset_submit_btn_clicked)
# 尺寸调整
self.size_view_btn.clicked.connect(self.size_view_btn_clicked)
self.size_submit_btn.clicked.connect(self.size_submit_btn_clicked) ####################################################################################################################
# 分辨率调整
####################################################################################################################
# 分辨率调整-源目录-浏览
def reslotion_src_view_btn_clicked(self):
directory = QFileDialog.getExistingDirectory(self, 'Src')
self.reslotion_src_le.setText(directory) # 分辨率调整-目标目录-浏览
def reslotion_dst_view_btn_clicked(self):
directory = QFileDialog.getExistingDirectory(self, 'Dst')
self.reslotion_dst_le.setText(directory) # 分辨率调整-确定
def reslotion_submit_btn_clicked(self):
self.reslotion_submit_btn.setEnabled(False)
t = threading.Thread(target=self.fact_convert_resolution)
t.start() # 分辨率调整-线程工作函数
def fact_convert_resolution(self):
try:
# 删除已经存在转换目标目录
wdire = self.reslotion_dst_le.text()
wdire = os.path.join(wdire, os.path.split(self.reslotion_src_le.text())[-1] + '_convert')
wdire = wdire.replace('\\', '/')
if os.path.exists(wdire): shutil.rmtree(wdire)
wdire = shutil.copytree(self.reslotion_src_le.text(), wdire)
rw, rh = float(self.reslotion_dstw_le.text()) / float(self.reslotion_srcw_le.text()), \
float(self.reslotion_dsth_le.text()) / float(self.reslotion_srch_le.text())
self.conver_resolution(wdire, rw, rh)
except: QMessageBox.information(self, 'Error', '请检查输入是否完整.')
self.output_lw_signal.emit('全部转换工作已经完成.')
self.reslotion_submit_btn.setEnabled(True) ####################################################################################################################
# 偏移值调整
####################################################################################################################
# 偏移值调整-序列文件夹-浏览
def offset_view_btn_clicked(self):
directory = QFileDialog.getExistingDirectory(self, 'Sequence')
self.offset_dire_le.setText(directory) # 偏移值调整-确定
def offset_submit_btn_clicked(self):
dire = self.offset_dire_le.text()
if dire == None:
QMessageBox.information(self, 'Error', '参数错误.')
return
if os.path.isdir(dire) == False:
QMessageBox.information(self, 'Error', '参数错误.')
return
# 遍历文件夹下的图片文件
self.offset_submit_btn.setEnabled(False)
# args是一个数组变量参数,如果只传递一个值,
# 就只需要i, 如果需要传递多个参数,那么还可以继续传递下去其他的参数,
# 其中的逗号不能少,少了就不是数组了,就会出错
t = threading.Thread(target=self.offset_submit_worker, args=(dire,))
t.start() # 偏移值调整-线程工作函数
def offset_submit_worker(self, dire):
if not self.offset_pixel_le.text(): pixel = int(self.offset_pixel_le.placeholderText())
else: pixel = int(self.offset_pixel_le.text())
if not self.offset_meter_le.text(): meter = int (self.offset_meter_le.placeholderText())
else: meter = int(self.offset_meter_le.text())
if not self.offset_ltx_le.text(): ltx = float(self.offset_ltx_le.placeholderText())
else: ltx = float(self.offset_ltx_le.text())
if not self.offset_lty_le.text(): lty = float(self.offset_lty_le.placeholderText())
else: lty = float(self.offset_lty_le.text())
# 计算偏移像素
offx = int(ltx * pixel / meter)
offy = int(lty * pixel / meter)
# print(offx, offy)
# self.output_lw_signal.emit('will process ' + dire)
try:
n = 0
for file in os.listdir(dire):
fn = os.path.join(dire, file)
fn = fn.replace('\\', '/')
# self.output_lw_signal.emit('->' + fn)
if os.path.isfile(fn):
# 分割文件名与文件扩展名
f,e = os.path.splitext(fn)
# 只针对带透明通道的图片
exts = ['.png', '.psd']
if e in exts:
s = Image.open(fn)
sw,sh = s.size
# 调整宽和高为64的倍数
# rw = math.ceil(sw/64.0)
# rh = math.ceil(sh/64.0)
# dw = 64 * rw
dw = sw + abs(int(2 * offx))
if (dw-sw)%2 == 1: dw+=1
# dh = 64 * rh
dh = sh + abs(int(2 * offy))
if (dh-sh)%2 ==1: dh+=1
# print(sw, sh, dw, dh, rw, rh)
# 创建一个容器图片
ns = Image.new('RGBA', (dw,dh))
# 原图无偏移区域
bx = int((dw-sw)/2) + offx
by = int((dh-sh)/2) + offy
# box = (bx,by,sw+bx,sh+by)
# 这里需要源图片尺寸要保持不变
# ns.paste(s,box)
ns.paste(s, (bx,by))
ns.save(fn)
ns.close()
s.close()
# 顺带改名
if self.rename_ckb.isChecked():
nf = os.path.join(os.path.split(fn)[0], '%04d'%(n) + e)
n = n + 1
os.rename(fn, nf)
fn = nf
self.output_lw_signal.emit('->' + fn)
except TypeError: print('Error', 'TypeError.')
except IOError: print('Error', 'IOError.')
except FileNotFoundError: print('Error', 'FileNotFoundError.')
self.offset_submit_btn.setEnabled(True)
self.output_lw_signal.emit('全部偏移工作已经完成.') # arg-目录 rw-宽度比值 rh-高度比值
def conver_resolution(self, arg, rw, rh):
if not os.path.isdir(arg) and not os.path.isfile(arg): return False
if os.path.isfile(arg):
# 分割出目录与文件
_strs = os.path.split(arg)
# 分割文件名与文件扩展名
_strs = _strs[-1].split('.')
exts = ['bmp', 'jpeg', 'jpg', 'png', 'psd']
if _strs[-1] in exts:
im = Image.open(arg)
w,h = im.size
rim = im.resize((int(w*rw),int(h*rh)), Image.ANTIALIAS)
rim.save(arg)
self.output_lw_signal.emit('->' + arg)
im.close()
rim.close()
elif os.path.isdir(arg):
for dire in os.listdir(arg):
# 向目录的下一级目录执行操作
narg = os.path.join(arg, dire)
narg = narg.replace('\\', '/')
self.conver_resolution(narg, rw, rh) ####################################################################################################################
# 尺寸调整
####################################################################################################################
# 尺寸调整-目录-浏览
def size_view_btn_clicked(self):
directory = QFileDialog.getExistingDirectory(self, '选择需要调整尺寸的目录')
self.size_directory_le.setText(directory) # 尺寸调整-确定
def size_submit_btn_clicked(self):
directory = self.size_directory_le.text()
if not directory:
self.output_lw_signal.emit('参数输入不完整.')
return
if not self.size_width_le.text():
self.output_lw_signal.emit('参数输入不完整.')
return
else: self.size_setw = int(self.size_width_le.text())
if not self.size_height_le.text():
self.output_lw_signal.emit('参数输入不完整.')
return
else: self.size_seth = int(self.size_height_le.text()) self.size_submit_btn.setEnabled(False)
t = threading.Thread(target=self.size_submit_btn_callback, args=(directory,))
t.start() # 尺寸调整-线程工作函数
def size_submit_btn_callback(self, directory):
self.output_lw_signal.emit('start process images.')
for file in os.listdir(directory):
compath = os.path.join(directory, file)
compath = compath.replace('\\', '/')
if os.path.isfile(compath):
# 分割出文件名与扩展名
f,e = os.path.splitext(compath)
# 确定操作的文件为图片
if e in ['.png', '.psd', '.jpg', '.jpeg','.bmp']:
im = Image.open(compath)
imw,imh = im.size
x = abs(int((imw - self.size_setw) / 2))
y = abs(int((imh - self.size_seth) / 2))
if im.size >= (self.size_setw, self.size_seth):
newim = im.crop((x, y, x + self.size_setw, y + self.size_seth))
else:
newim = Image.new('RGBA', (self.size_setw, self.size_seth))
newim.paste(im, (x, y))
newim.save(compath)
newim.close()
im.close()
self.output_lw_signal.emit(compath + ' process success.')
self.size_submit_btn.setEnabled(True)
self.output_lw_signal.emit('all process is completed.') ####################################################################################################################
# comm
####################################################################################################################
def output_lw_signal_proc(self, arg):
self.output_lw.addItem(arg)
self.output_lw.scrollToBottom() def reslotion_submit_signal_proc(self):
self.reslotion_submit_btn.setEnabled(True)
- 程序入口
# coding=utf-8
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from IProcessingDialogWrap import IPDW if __name__ == '__main__':
app = QApplication(sys.argv)
ip = IPDW()
ip.show()
sys.exit(app.exec_())