from cjm_pil_utils.core import get_img_files
from pathlib import Path
cjm-pil-utils
Some PIL utility functions I frequently use.
Install
pip install cjm_pil_utils
How to use
get_img_files
= Path('../images/')
img_dir = get_img_files(img_dir)
img_paths img_paths
[PosixPath('../images/cat.jpg'), PosixPath('../images/depth-cat.png')]
resize_img
from cjm_pil_utils.core import resize_img
from PIL import Image # For working with images
= img_paths[0]
img_path = Image.open(img_path).convert('RGB')
src_img print(f"Image Size: {src_img.size}")
= resize_img(src_img, target_sz=384, divisor=32)
resized_img print(f"New Image Size: {resized_img.size}")
Image Size: (768, 512)
New Image Size: (576, 384)
stack_imgs
from cjm_pil_utils.core import stack_imgs
= stack_imgs([resized_img, resized_img])
stacked_imgs print(f"Stacked Image Size: {stacked_imgs.size}")
Stacked Image Size: (576, 768)
avg_images
from cjm_pil_utils.core import avg_images
= (Image.open(path) for path in img_paths)
img_1, img_2 = avg_images(img_1, img_2, 0.5) avg_img
crop_square
from cjm_pil_utils.core import crop_square
crop_square(src_img).size
(512, 512)