pilgram: Instagram-like Image Filters

2.0.0 · active · verified Thu Apr 16

pilgram is a Python library that applies Instagram-like photo filters, CSS filters, and blend modes to images. It leverages the Pillow library for image manipulation. The current version, 2.0.0, requires Python 3.10+ and Pillow 10.3.0+. The library maintains an active development and release schedule.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to load an image, apply an Instagram-like filter, a CSS filter, and a blend mode. It creates dummy images if input files are not found, ensuring the code is runnable out-of-the-box.

from PIL import Image
import pilgram
import os

# Create a dummy image if 'sample.jpg' does not exist
if not os.path.exists('sample.jpg'):
    print("Creating dummy 'sample.jpg' for demonstration.")
    img = Image.new('RGB', (600, 400), color = 'red')
    img.save('sample.jpg')

# Load an image
im = Image.open('sample.jpg')

# Apply an Instagram-like filter (e.g., Aden)
pilgram.aden(im).save('sample-aden.jpg')
print("Applied 'aden' filter, saved as 'sample-aden.jpg'")

# Apply a CSS filter (e.g., sepia)
import pilgram.css
pilgram.css.sepia(im).save('sample-sepia.jpg')
print("Applied CSS 'sepia' filter, saved as 'sample-sepia.jpg'")

# Apply a blend mode (requires two images)
if not os.path.exists('backdrop.jpg'):
    print("Creating dummy 'backdrop.jpg' for demonstration.")
    backdrop = Image.new('RGB', (600, 400), color = 'blue')
    backdrop.save('backdrop.jpg')
else:
    backdrop = Image.open('backdrop.jpg')

if not os.path.exists('source.jpg'):
    print("Creating dummy 'source.jpg' for demonstration.")
    source = Image.new('RGB', (600, 400), color = 'green')
    source.save('source.jpg')
else:
    source = Image.open('source.jpg')

import pilgram.css.blending
pilgram.css.blending.color(backdrop, source).save('blending.jpg')
print("Applied 'color' blend mode, saved as 'blending.jpg'")

view raw JSON →