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:
- ModuleNotFoundError: No module named ‘tensorflow.python’ And the pits encountered after installation
- Python asynchronous execution library asyncio
- Python traverses all files under the specified path and retrieves them according to the time interval
- Extracting Data from XML (Using Python to Access Web Data)
- Python raspberry pie starts sending IP address to mailbox
- Django WSGI protocol application, based on wsgiref module DIY a web framework
- Python recursively traverses all files in the directory to find the specified file
- An introduction to sys modules in Python and how packages are imported and used
- RuntimeWarning: overflow encountered in ubyte_Scalars pixel addition and subtraction overflow exception
- Python synthesizes multiple pictures into one video
- The Python DOM method iterates over all the XML in a folder
- Here is the difference and connection of Torch. View (), Transpose (), and Permute ()
- python: File Processing and Input and Output
- Python openpyxl excel open zipfile error resolution: zipfile.BadZipFile: File is not a zip file
- Python ValueError: only 2 non-keyword arguments accepted
- Python uses try… Except… To output detailed errors
- When sending HTTP request, python encountered: error 54, ‘connection reset by peer’ solution
- Opencv: How to Draw Palette
- Python: RNN principle realized by numpy
- Python: How to Create an Automatic Recording Program