PIL输出图片大于输入
PIL output picture bigger than input
我目前正在开发一个自动脚本,用于使用 PIL (python) 更改文件夹内所有图片的对比度。问题是每张输出图片都比输入一张大...这是我的脚本:
from PIL import Image, ImageEnhance
import piexif
path="C:/User/pictures/"
all_files=["picture1.jpg", "picture2.jpg", "picture3.jpg"]
for i in range(len(all_files)):
im_path=all_files[i]
im = Image.open(path+im_path)
#load exif data
exif_dict = piexif.load(im.info['exif'])
exif_bytes = piexif.dump(exif_dict)
dpi = im.info["dpi"]
#image brightness enhancer
contraster = ImageEnhance.Contrast(im)
im_output = contraster.enhance(factor)
im_output.save(new_path+im_path, format="JPEG", quality=100, dpi=dpi, exif=exif_bytes, subsampling=0)
比如我传入的jpg图片是8.08Mo,新的是15.8Mo,即使我选择了0%的对比度变化...
感谢a的回答,周末愉快
您已针对图书馆作者的 recommendations 指定 quality=100
。
The image quality, on a scale from 0 (worst) to 95 (best). The default is 75. Values above 95 should be avoided; 100 disables portions of the JPEG compression algorithm, and results in large files with hardly any gain in image quality.
我目前正在开发一个自动脚本,用于使用 PIL (python) 更改文件夹内所有图片的对比度。问题是每张输出图片都比输入一张大...这是我的脚本:
from PIL import Image, ImageEnhance
import piexif
path="C:/User/pictures/"
all_files=["picture1.jpg", "picture2.jpg", "picture3.jpg"]
for i in range(len(all_files)):
im_path=all_files[i]
im = Image.open(path+im_path)
#load exif data
exif_dict = piexif.load(im.info['exif'])
exif_bytes = piexif.dump(exif_dict)
dpi = im.info["dpi"]
#image brightness enhancer
contraster = ImageEnhance.Contrast(im)
im_output = contraster.enhance(factor)
im_output.save(new_path+im_path, format="JPEG", quality=100, dpi=dpi, exif=exif_bytes, subsampling=0)
比如我传入的jpg图片是8.08Mo,新的是15.8Mo,即使我选择了0%的对比度变化...
感谢a的回答,周末愉快
您已针对图书馆作者的 recommendations 指定 quality=100
。
The image quality, on a scale from 0 (worst) to 95 (best). The default is 75. Values above 95 should be avoided; 100 disables portions of the JPEG compression algorithm, and results in large files with hardly any gain in image quality.