Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

Gray-Ice

个人博客兼个人网站

需要导入python的cv2库

pip导入:

1
pip install opencv-python

下面是代码:

1
2
3
4
5
6
7
8
9
10
import cv2

# 图像压缩
def compressed_picture(pic_path, new_filename):
img = cv2.imread(pic_path)

# 压缩 0-9等级越高压缩幅度越大,相应的像素损失越大, 0是无压缩
cv2.imwrite(new_filename, img, [cv2.IMWRITE_PNG_COMPRESSION, 5])
# 这个压缩的幅度更大,50为压缩到原本图片的一半数据量,10为压缩到原本图片的10%数据量(然而实际效果似乎并非如此)
cv2.imwrite(new_filename, img, [cv2.IMWRITE_JPEG_QUALITY, 50])

评论



愿火焰指引你