Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取枕头中照片的总大小?_Python_Python 3.x_Image_Python Imaging Library - Fatal编程技术网

Python 如何获取枕头中照片的总大小?

Python 如何获取枕头中照片的总大小?,python,python-3.x,image,python-imaging-library,Python,Python 3.x,Image,Python Imaging Library,我想得到照片的总大小(MB),但我只得到ExifImageWidth和ExifImageHeight。 我该怎么做 代码: from PIL import Image from PIL.ExifTags import TAGS image = Image.open('images\DJI_0001.jpg') exifdata = image.getexif() for tag_id in exifdata: tag = TAGS.get(tag_id, tag_id) d

我想得到照片的总大小(MB),但我只得到ExifImageWidth和ExifImageHeight。 我该怎么做

代码:

from PIL import Image
from PIL.ExifTags import TAGS

image = Image.open('images\DJI_0001.jpg')

exifdata = image.getexif()

for tag_id in exifdata:
    tag = TAGS.get(tag_id, tag_id)
    data = exifdata.get(tag_id)
    if isinstance(data, bytes):
        try:
            data = data.decode()
        except:
            continue
    print(f"{tag}: {data}")

试试
file\u size=os.stat('d:/file.jpg')
,然后是
print(“文件大小:”,file\u size.st\u size,“字节”)
顺便说一句,你可能想要
MB
(兆字节)而不是
MB
(毫位)@MarkSetchell是的,你有权利。我将更正这个.sys.getsizeof(对象[,默认]):它将转换为sys.getsizeof(您的图像),而不是从字节转换为MB