local image
from urllib import request
from PIL import Image
import os
import numpy as np
import requests,io
dirpath = r"E:\图片集\0\图片大小"
filenames = os.listdir(dirpath)
for filename in filenames[:]:
portion = os.path.splitext(filename) # 将文件名和缀名分成俩部分
filepath = os.path.join(dirpath, filename)
with open(filepath, "rb") as f:
size = len(f.read())
print("{}图片的大小{} byte,{} kb,{} Mb".format(filename,size, size/1e3, size/1e6))
results:
image url </ strong> </ p>
import requests,io
urls = ['http://******/image/0826/2411kb.png',
'http://******/image/0826/2026kb.png',
'http://******/image/0826/1968kb.png']
for url in urls:
image = requests.get(url).content
image_b = io.BytesIO(image).read()
size = len(image_b)
print("{}的大小{} byte,{} kb,{} Mb".format(url,size, size/1e3, size/1e6))
results:
Note: as can be seen from the above screenshot, byte/ KB /Mb values obtained from both the local image fetch size and url fetch size are larger than those seen on the computer. I don’t know why, but if anyone knows, please help to solve </p b>
Read More:
- [Solved] ParserError: NULL byte detected. This byte cannot be processed in Python‘s native csv library
- CV: How to extracts the part of the picture with the specified color
- [Solved] Huawei OBS Python SDK download picture error: nosuchkey
- [Solved] UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xbf in position 7: invalid start byte
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- [PHP] Solve PHP Fatal error: Call to undefined function mcrypt_get_iv_size()
- [Solved] Python opencv imshow Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow
- How to Solve Pytorch DataLoader Loading Error: UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe5 in position 1023
- Python: How to Delete Empty Files or Folders in the Directory
- Python: How to Disable InsecureRequestWarning error
- [Solved] error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow‘
- Linux Fatal Python error: Py_Initialize Unable to get the locale encoding
- [Solved] RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dim
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- [Python] Right-click Selenium to Save the picture error: attributeerror: solution to module ‘pyscreen’ has no attribute ‘locationonwindow’
- Python: How to Use os.path.join()
- [Solved] Fatal Python error: initfsencoding: Unable to get the locale encoding
- [Solved] Python matplotlib Error: RuntimeError: In set_size: Could not set the fontsize…
- Python: How to parses HTML, extracts data, and generates word documents