You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
|
# 打开图片
|
|
|
|
|
img = Image.open(r'D:\backup\02f89961-90a8-07b0-6613-0b733f5c321e.jpg')
|
|
|
|
|
|
|
|
|
|
# 获取图片属性
|
|
|
|
|
width, height = img.size
|
|
|
|
|
dpi = img.info.get('dpi')
|
|
|
|
|
mode = img.mode
|
|
|
|
|
|
|
|
|
|
print(f"图片尺寸: {width}x{height}")
|
|
|
|
|
print(f"DPI: {dpi}")
|
|
|
|
|
print(f"颜色模式: {mode}")
|
|
|
|
|
|
|
|
|
|
# 设置压缩质量(1-95,95为最高质量)
|
|
|
|
|
quality = 90
|
|
|
|
|
# 保存压缩后的图片
|
|
|
|
|
img.save(r'D:\backup\02f89961-90a8-07b0-6613-0b733f5c321e_new.jpg', 'JPEG', quality=quality)
|
|
|
|
|
|
|
|
|
|
print("=====")
|
|
|
|
|
img = Image.open(r'D:\backup\021d1281-9d0b-3acf-fc8b-1b86ff6e9832.jpg')
|
|
|
|
|
|
|
|
|
|
# 获取图片属性
|
|
|
|
|
width, height = img.size
|
|
|
|
|
dpi = img.info.get('dpi')
|
|
|
|
|
mode = img.mode
|
|
|
|
|
|
|
|
|
|
print(f"图片尺寸: {width}x{height}")
|
|
|
|
|
print(f"DPI: {dpi}")
|
|
|
|
|
print(f"颜色模式: {mode}")
|