I want to the image size of an image in megabyte or kilobyte. This type of question has been asked before and a solution wasn't really provided. NOTE:i'm not concerned with the image width and height, just the file size in megabyte or kilobytes because i'm working on the image for user input validation so its on the fly.
This is my code:
from PIL import Image
images = request.FILES.getlist('files')
memory_upload = []
for x in range(len(images)):
img = images[x]
#image upload input validator for extension
if img.name.split('.')[1] in accept_ext:
im = Image.open(img)
print(im.size)
The result for the images in size in pillow is in width and height format: (3696, 4620) But i need to know the size in megabytes so as to prevent the image from being compressed if the file is huge to restrict something like a DoS attack on the server