Possible Duplicate:
How to check dimensions of all images in a directory using python?
I was wondering if somebody knows how can I read an image total amount of pixels in a python sript. Could you provide and example?
Thanks a lot.
Use PIL to load the image. The total number of pixels will be its width multiplied by its height.
open() is used to open the image and then . width and . height property of Image are used to get the height and width of the image.
here is an example:
from PIL import Image
def get_num_pixels(filepath):
width, height = Image.open(filepath).size
return width*height
print(get_num_pixels("/path/to/my/file.jpg"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With