Block 47: Image Basics with Pillow
Open, inspect, and transform images programmatically.
Concepts
- from PIL import Image
- Image.open(), img.size, img.mode
- img.resize(), img.rotate(), img.crop()
- img.save() to various formats
Code Examples
See exercise below.
Exercise
Open an image, print its size and mode, create a thumbnail, save as PNG. Convert an RGB image to grayscale.
Homework
What does img.mode tell you? What is the difference between 'RGB', 'L', and 'RGBA'?