Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import numpy as np
from PIL import Image, ImageOps, ImageChops
img = Image.open("../../home/media/poker/4h.png")
img
<PIL.PngImagePlugin.PngImageFile image mode=RGB size=37x54 at 0x7FF066939320>

ImageChops.offset

Shift to the left with 10 pixels.

ImageChops.offset(img, -10, 0)
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F28611CB518>

Image.crop and ImageOps.pad

img.crop((10, 0, 37, 54))
<PIL.Image.Image image mode=RGB size=27x54 at 0x7F28611FC6D8>
img_crop = img.crop((10, 0, 37, 54))
ImageOps.pad(img_crop, img.size, color="white", centering=(0, 0))
<PIL.Image.Image image mode=RGB size=37x54 at 0x7F28611D7160>
img_crop = img.crop((10, 0, 37, 54))
ImageOps.pad(img_crop, img.size, color="black", centering=(0, 0))
<PIL.Image.Image image mode=RGB size=37x54 at 0x7FF066818AC8>

Image.crop and ImageOps.fit

img_crop = img.crop((10, 0, 37, 54))
ImageOps.pad(img_crop, img.size, method=0, centering=(0, 0))
<PIL.Image.Image image mode=RGB size=37x54 at 0x7FF0668181D0>