Quick answers

Short fixes for errors that do not need a full page.

MemoryError

Out of memory processing large images

Cause: Large images are decoded fully into RAM before processing.

Fix: Use JPEG draft mode, downscale early, or process in tiles.

img = Image.open("huge.jpg")
img.draft("RGB", (800, 600))   # JPEG only
img.load()
Orientation

Image appears rotated after opening

Cause: Cameras store rotation in the EXIF Orientation tag; Pillow does not auto-rotate on open.

Fix: Apply the EXIF transpose.

from PIL import ImageOps
img = ImageOps.exif_transpose(img)
ValueError

images do not match

Cause: ImageChops operations require both images to have identical size and mode.

Fix: Normalise size and mode before combining.

b = b.convert(a.mode).resize(a.size)
result = ImageChops.difference(a, b)
TypeError

'Image' object is not subscriptable / cannot slice

Cause: Treating a Pillow Image like a NumPy array.

Fix: Convert explicitly, or use getpixel().

import numpy as np
arr = np.array(img)            # to array
crop = img.crop((0, 0, 100, 100))
PermissionError

Permission denied when saving

Cause: The output file is open in another program, or the target directory is not writable.

Fix: Close the file, or write to a different path / ensure the directory exists.

import os
os.makedirs("out", exist_ok=True)
img.save("out/result.png")
ImportError

cannot import name 'ImageDraw' from 'PIL'

Cause: Usually a file or folder named PIL (e.g. PIL.py) in your project is shadowing the real package; the error message shows its path. Also seen with a broken or partial install.

Fix: Rename your PIL.py, or reinstall Pillow. Then import submodules explicitly.

from PIL import Image, ImageDraw, ImageFont