KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
Lossless-image-compression
★ 20
Open GitHub ↗
利用python的Image库对图片进行无损压缩
Download README (.md)
Explore Similar Repositories
LASSO-MPC
:
PhD Publications and Thesis on LASSO Model Predictive Control
imgui-opencv
:
Use opencv, imgui and poco libraries in a project with Conan
spring-animation-keyframes
:
Generate css keyframes based on spring animations
aws-cloudformation-security-automation-for-wazuh
:
NIST based open source security automation delivered as AWS cloudformation
RTHS
:
Real-Time Hardware Sorter, Using A Multi-Dimensional Sorting Algorithm
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
Lossless-image-compression
?
Download (.md)
# 使用python自带的Image库实现压缩 ## 原理 程序会自动遍历当前文件夹及子文件夹下的所有图片文件 说来也巧,这也是之前用Image库处理图片的时候偶然发现的.我发现用Image库打开图片后再原封不动的另存为新文件后文件所占体积大大减小. 程序流程如下: `备份图片->打开图片->保存图片?删除备份图片:跳过` ## 手动打包py文件 虽然我上面有发exe文件可以直接在Windows上运行,但我还是鼓励你自己打包.不管是从技术上还是安全上讲. 使用以下命令将代码打包成可执行文件 ```shell #安装 pyinstaller(打包工具) Pillow(图片处理库) pip install pyinstaller pip install Pillow #进入到项目目录下 #开始打包 -F 是打包成一个单独的文件 pyinstaller -F img.py #显示success字样就说明成功了 #在项目根目录下会生成很多文件,生成的exe文件就在dist文件夹下 ``` ## 效果&效率 测试了下1.55G的壁纸,用时1分45秒.转换后大小为117M 因为是把<<你的名字>>电影抽帧抽出来当壁纸用的图片,所以压缩起来效果拔群.平时自己的照片可能没那么夸张 转换应该是无损的,肉眼可能能看出那么一丢丢的区别.建议先建个文件夹试一下,如果介意就不要转换.注意程序会自动遍历当前文件夹及子文件夹中的所有图片 ## 注意 最好在转换前备份图片以防意外. 在转换的过程中不免会出现意外情况,这并不会导致数据丢失.而是会留下一个带有后缀名的垃圾文件.把它删除即可.