吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4094|回复: 46
收起左侧

[Python 原创] 增大jpg图像的文件大小

  [复制链接]
liyitong 发表于 2022-4-10 18:01
本帖最后由 liyitong 于 2022-11-14 21:16 编辑

上传一个考试证件,调整为规定的分辨率后,画质拉倒100%,图像也不够规定的大小(100KB~200KB)
所以做了个软件,核心思想是利用
[Asm] 纯文本查看 复制代码
1
copy /b file1.jpg+file2 new.jpg
这样new.jpg会显示file1.jpg的样子,但是体积是两个文件的和。
ui文件不再废话,直接用qtdesigner拖曳一下,然后用ui2py生成py文件,在run文件中import即可。
[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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_())
QQ截图20220410175434.png
QQ截图20220410175415.png
下载地址:
https://liyitong.lanzout.com/iXYyQ02yhnsf

免费评分

参与人数 10吾爱币 +14 热心值 +8 收起 理由
azoth07 + 1 + 1 我很赞同!
梦影工作室 + 1 + 1 特此来感谢作者的,一个报名照片折腾了3个小时都达不到要求,用此工具完美.
wushaominkk + 5 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
chmwyy + 1 + 1 谢谢@Thanks!
烟花非易冷 + 1 热心回复!
wirhttn + 1 谢谢@Thanks!
yanglinman + 1 谢谢@Thanks!
ruanxikun + 1 + 1 我很赞同!
HelloHi + 2 + 1 用心讨论,共获提升!
wuailisure + 1 + 1 谢谢你让我的电脑爆红 不过谢谢分享 学习学习

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

噫哥哥 发表于 2022-4-10 18:13
是个占空间的好方法
smileat2000 发表于 2022-4-10 18:06
LouisTong 发表于 2022-4-10 18:16
從來都是嫌文件太大的,第一次聽說有網站嫌文件太小的
為什麼會有這種規定?
落红护花 发表于 2022-4-10 18:18
好奇特啊,都是压缩体积,为什么要限制最小啊
 楼主| liyitong 发表于 2022-4-10 18:24
落红护花 发表于 2022-4-10 18:18
好奇特啊,都是压缩体积,为什么要限制最小啊

压缩体积的代码是牺牲画质。
文件太小了,肯定画质会很模糊。
落红护花 发表于 2022-4-10 18:25
liyitong 发表于 2022-4-10 18:24
压缩体积的代码是牺牲画质。
文件太小了,肯定画质会很模糊。

简单的合并增大也不会增强画质吧
头像被屏蔽
xiadongming 发表于 2022-4-10 18:27
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| liyitong 发表于 2022-4-10 18:42
落红护花 发表于 2022-4-10 18:25
简单的合并增大也不会增强画质吧

问题现在是最高画质了还不够大——

现在的目标是把证件照上传上去,我们并不是在解决画质问题
天才笨蜀黍 发表于 2022-4-10 18:45
确实存在这种奇葩的强制性要求~~
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-19 10:31

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表