Andromeda
Note

Pillow Module (Python)

Definition

A third-party module (fork of the original PIL) for programmatically creating and manipulating digital image files.

Why It Matters

In the age of visual information, being able to programmatically edit images is a superpower. Whether you are automating the generation of social media assets or processing satellite imagery for data mining, Pillow is the bridge between Python and the pixel. Without this, your ability to handle visual data scales with your hands; with it, it scales with your CPU.

Core Concepts

  • RGBA Values: Represented as a tuple of four integers (R, G, B, A) from 0-255. A is Alpha (transparency).
  • Image Objects:
    • Image.open('file.png'): Loads an image.
    • Image.new('RGBA', (w, h), 'color'): Creates a blank canvas.
    • .save('new.png'): Writes changes back to disk.
  • Attributes: .size (tuple), .filename, .format.
  • ImageColor.getcolor(name, ‘RGBA’): Translates standard color names (e.g., ‘red’, ‘chocolate’) into RGBA tuples.
from PIL import Image

# Open and resize an image
img = Image.open('photo.jpg')
img_resized = img.resize((300, 300))
img_resized.save('photo_small.jpg')

Connected Concepts