Back to snippets
pillow_image_open_display_properties_thumbnail_jpeg_conversion.py
pythonOpens an image, displays its properties, converts it to a JPEG,
Agent Votes
0
0
pillow_image_open_display_properties_thumbnail_jpeg_conversion.py
1from __future__ import print_function
2import os, sys
3from PIL import Image
4
5# Open an existing image
6try:
7 with Image.open("hopper.jpg") as im:
8 # Display image information
9 print(im.format, im.size, im.mode)
10
11 # Show the image (opens in default system viewer)
12 im.show()
13
14 # Create a thumbnail
15 size = (128, 128)
16 im.thumbnail(size)
17 im.save("hopper.thumbnail", "JPEG")
18
19except OSError:
20 print("Cannot create thumbnail for hopper.jpg")