本帖最后由 liyitong 于 2022-11-14 21:16 编辑
上传一个考试证件,调整为规定的分辨率后,画质拉倒100%,图像也不够规定的大小(100KB~200KB)
所以做了个软件,核心思想是利用[Asm] 纯文本查看 复制代码 copy /b file1.jpg+file2 new.jpg 这样new.jpg会显示file1.jpg的样子,但是体积是两个文件的和。
ui文件不再废话,直接用qtdesigner拖曳一下,然后用ui2py生成py文件,在run文件中import即可。[Python] 纯文本查看 复制代码 import sys
import os
import base64 #释放要使用的附加文件
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox, QLineEdit, QFileDialog
from PyQt5 import QtWidgets, QtCore
from tupianzengda import Ui_MainWindow
from file50_jpg import img as file50 #50KB大小的,预先把img给base64后存到py中。
from file100_jpg import img as file100 #100KB大小的
from file150_jpg import img as file150 #150KB大小的
class my(Ui_MainWindow):
def __init__(self):
self.file_name=sys.argv
self.file_fujia="file100.jpg"
self.daxiao=0 #50KB
def setupUi(self, MainWindow):
super(my, self).setupUi(MainWindow)
self.pushButton.clicked.connect(self.wenjianxuanze)
self.pushButton_2.clicked.connect(self.tuxiangchuli)
#self.comboBox.mousePressEvent.connect(self.daxiaoxuanze)
def wenjianxuanze(self):
self.mulu=os.getcwd()
if not os.path.exists("file50.data"):
tmp = open("file50.data", 'wb')
tmp.write(base64.b64decode(file50))
tmp.close()
if not os.path.exists("file100.data"):
tmp = open("file100.data", 'wb')
tmp.write(base64.b64decode(file100))
tmp.close()
if not os.path.exists("file150.data"):
tmp = open("file150.data", 'wb')
tmp.write(base64.b64decode(file150))
tmp.close() #生成要混合的数据包大小
file_name, file_type=QFileDialog.getOpenFileName(None,"选择图像文件", self.mulu, "图像文件 (*.jpg *.jpeg *.png *.bmp *.gif)")
if file_name=="":
self.statusBar.showMessage("没有选中任何文件")
else:
self.lineEdit.setText(file_name)
self.statusBar.showMessage("已经选中了目标文件,大小是%.fKB"%(os.path.getsize(file_name)/1024) )
def daxiaoxuanze(self):
daxiao_filename=['file50.data','file100.data','file150.data']
self.file_fujia=daxiao_filename[self.comboBox.currentIndex()]
def tuxiangchuli(self):
self.daxiaoxuanze()
file_old=self.lineEdit.text()
if len(file_old)==0:
self.lineEdit.setText("还没有选择要修改的图像文件")
return
file_old_name =file_old.split(r'/')[-1]
file_new= file_old_name.split(r'.')[0]+ "_add"+self.comboBox.currentText()+".jpg"
print(file_old_name, file_new)
os.chdir(os.getcwd() )
print(os.getcwd())
zhixing=r"copy /b "+ file_old.replace('/',r'\\') + "+" + self.file_fujia+" "+file_new#py执行不需要replace,gui需要
print(zhixing)
jieguo=os.popen(zhixing)
print(jieguo.read())
old_size=os.path.getsize(file_old)/1024
new_size=os.path.getsize(file_new)/1024
self.statusBar.showMessage("原文件大小:%.0fKB 处理后大小:%.0fKB"%(old_size, new_size ))
os.system("explorer.exe %s" %(os.getcwd() ) )
myapp=QApplication(sys.argv)
mydlg=QtWidgets.QMainWindow()
myui=my()
myui.setupUi(mydlg)
mydlg.show()
sys.exit(myapp.exec_())
下载地址:
https://liyitong.lanzout.com/iXYyQ02yhnsf |