xxxxxxxxxx
from PIL import Image
im = Image.open('whatever.png')
width, height = im.size
xxxxxxxxxx
from PIL import Image
im = Image.open('data/src/lena.jpg')
print(im.size)
print(type(im.size))
# (400, 225)
# <class 'tuple'>
w, h = im.size
print('width: ', w)
print('height:', h)
# width: 400
# height: 225
xxxxxxxxxx
from PIL import Image
# Open the image
image = Image.open("path/to/image.jpg")
# Resize the image while preserving the aspect ratio
new_size = (500, 500) # Specify the desired new size
resized_image = image.resize(new_size)
# Save the resized image
resized_image.save("path/to/resized_image.jpg")
xxxxxxxxxx
from PIL import Image
# Open the image file
image = Image.open('path_to_image.jpg')
# Get the size of the image
image_size = image.size
# Extract the dimensions
width, height = image_size
print(f"Image width: {width}")
print(f"Image height: {height}")