PILKit

3.0 · active · verified Wed Apr 15

PILKit is a collection of utilities and processors built on top of the Python Imaging Library (PIL), primarily Pillow. It simplifies common image manipulation tasks by providing an easy-to-use API for operations like resizing, adjusting, and cropping. The current stable version is 3.0, released in September 2023, and the library maintains an active development cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use a PILKit processor (ResizeToFit) to modify an image. It also shows the recommended way to save the processed image using `pilkit.utils.save_image` to handle potential PIL errors. Ensure Pillow is installed before running.

import os
from PIL import Image
from pilkit.processors import ResizeToFit
from pilkit.utils import save_image

# Create a dummy image for demonstration
try:
    img = Image.new('RGB', (200, 150), color = 'red')
    img.save('original_image.png')
except ImportError:
    print("Pillow not installed. Please install it with 'pip install Pillow'.")
    exit()

# Define a processor
processor = ResizeToFit(width=100, height=100, upscale=False)

# Process the image
original_image = Image.open('original_image.png')
processed_image = processor.process(original_image)

# Save the processed image using pilkit's utility
save_image(processed_image, 'processed_image.png', 'PNG')

print("Original image saved as original_image.png")
print("Processed image (resized to fit 100x100) saved as processed_image.png")

# Clean up (optional)
os.remove('original_image.png')
os.remove('processed_image.png')

view raw JSON →