Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read how many pixels an image has in Python [duplicate]

Tags:

python

pixels

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.

like image 507
user175259 Avatar asked Oct 15 '09 23:10

user175259


People also ask

How do you count the number of pixels in an image in Python?

Use PIL to load the image. The total number of pixels will be its width multiplied by its height.

How do I find the size of an image in Python?

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.


1 Answers

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"))
like image 86
pcardune Avatar answered Sep 30 '22 15:09

pcardune