The number of pixels in an image is called the image resolution. Resolution is often represented by the width and height of the image in pixels, and multiplying these numbers with one another gets you the total number of pixels. For example, an image that is 1024 pixels wide and 798 pixels high contains 1024 × 798 = 817152 pixels.
Download this folder onto your desktop.
Complete This Document
Your goal is to find the total size of the smiley image, inclusive of its bit depth. Once again, open up the smiley image you downloaded for this step’s first activity.
Find the resolution by multiplying the height by the width
Calculate the file size of the smiley image using the following bit depths:
a. 1
b. 2
c. 8
d. 16
e. 24
This Python script works out the width and height of an image:
from PIL import Image
im = Image.open('myimage.png') #path to image file
width, height = im.size
resolution = width * height
print("The image resolution is: ", width, " x ", height)
print("The resolution is: ", resolution)
Can you extend the code to:
Calculate the resolution of another file?
Ask the user to input a fixed bit depth and then update your output calculation to include it?
Calculate the file sizes of all the images within a given folder?
Research task: can you write/find some code to make the Python script automatically find the bit depth of the image(s)?