调整大小后如何在python-pillow中获取图像大小? [英] How to get image size in python-pillow after resize?

查看:1109
本文介绍了调整大小后如何在python-pillow中获取图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

resized_image = Image.resize((100,200));

Image是Python枕头图像类,我已经使用resize函数来调整原始图像的大小,

Image is Python-Pillow Image class, and i've used the resize function to resize the original image,

如何找到resized_image的新文件大小(以字节为单位),而不必保存到磁盘然后再次读取

How do i find the new file-size (in bytes) of the resized_image without having to save to disk and then reading it again

推荐答案

该文件不必写入磁盘.像对象这样的文件可以达到目的:

The file doesn't have to be written to disk. A file like object does the trick:

from io import BytesIO

# do something that defines `image`...   
img_file = BytesIO()
image.save(img_file, 'png')
print(img_file.tell())

这会打印以PNG格式保存的图像的大小(以字节为单位),而不保存到磁盘.

This prints the size in bytes of the image saved in PNG format without saving to disk.

这篇关于调整大小后如何在python-pillow中获取图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆