pil image size code example

Example 1: python pil resize image

from PIL import Image

# Image.open() can also open other image types
img = Image.open("some_random_image.jpg")
# WIDTH and HEIGHT are integers
resized_img = img.resize((WIDTH, HEIGHT))
resized_img.save("resized_image.jpg")

Example 2: width and height of pil image

image = PIL.Image.open("sample.png")
width, height = image.size

Example 3: pil get image size

from PIL import Image

im = Image.open('whatever.png')
width, height = im.size

Example 4: python get image size

from PIL import Image

img = Image.open('path/to/image')
width, height = img.size
im.close()

Example 5: pil resize image

im = Image.open('image.jpg')  
im = im.resize((w, h))

Example 6: save imag epillow

im.save(file + ".thumbnail", "JPEG")