Skip to main content

A simple Python package for creating image grids with PIL (Pillow).

Project description

Pillow-de

A simple Python package for creating image grids with PIL (Pillow).

Installation

pip install pillow-de.

Or install dependencies:

pip install -r requirements.txt

Usage

You can use pillow-de either as a Python library or as a command-line tool.

Command-Line Usage

After installation, you can use the pillow-de command:

# Create a 2x3 grid from images
pillow-de img1.jpg img2.jpg img3.jpg img4.jpg img5.jpg img6.jpg -o grid.png --rows 2 --cols 3

# Auto-sized grid with labels (comma-separated)
pillow-de *.jpg -o output.png --labels "Cat,Dog,Bird,Fish"

# Load labels from text file (one label per line)
pillow-de *.jpg -o output.png --labels labels.txt

# Grid with row and column labels
pillow-de *.png -o grid.png --rows 2 --cols 2 \
  --x-labels "Col 1,Col 2" --y-labels "Row 1,Row 2"

# Load column labels from file
pillow-de *.png -o grid.png --x-labels columns.txt --y-labels rows.txt

# Custom spacing and font size
pillow-de img*.jpg -o grid.png --spacing 20 --font-size 16

# See all options
pillow-de --help

Python Library Usage

Basic Usage

from pillow-de import grid
from PIL import Image

# Create some example images or load from files
images = [
    Image.new('RGB', (100, 100), 'red'),
    Image.new('RGB', (100, 100), 'green'),
    Image.new('RGB', (100, 100), 'blue'),
    Image.new('RGB', (100, 100), 'yellow'),
]

# Create a 2x2 grid
my_grid = grid(images, rows=2, cols=2)

# Save the grid
my_grid.save('my_grid.png')

# Show the grid
my_grid.show()

With Row and Column Labels

from pillow-de import grid

# Create grid with row and column labels
my_grid = grid(
    images=['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg'],
    rows=2, 
    cols=2,
    x_labels=['Column 1', 'Column 2'],
    y_labels=['Row 1', 'Row 2'],
    spacing=15,
    font_size=14,
    x_labels_max_lines=1,  # Allow up to 1 line for column labels
    y_labels_max_lines=2   # Allow up to 2 lines for row labels
)

my_grid.save('labeled_grid.png')

With Custom Alignment

from pillow-de import grid

# Create grid with left-aligned x_labels and right-aligned y_labels
my_grid = grid(
    images=['image1.jpg', 'image2.jpg', 'image3.jpg', 'image4.jpg'],
    rows=2, 
    cols=2,
    x_labels=['Long Column Label 1', 'Long Column Label 2'],
    y_labels=['Long Row Label 1', 'Long Row Label 2'],
    x_labels_align='left',      # Left-align column labels
    y_labels_align='right',     # Right-align row labels
    x_labels_max_lines=2,
    y_labels_max_lines=1
)

my_grid.save('aligned_grid.png')

With Individual Image Labels

from pillow-de import grid

# Create grid with labels under each individual image
my_grid = grid(
    images=['cat.jpg', 'dog.jpg', 'bird.jpg', 'fish.jpg'],
    labels=['Fluffy Cat', 'Golden Retriever', 'Blue Jay', 'Goldfish'],
    rows=2, 
    cols=2,
    labels_max_lines=2,
    labels_align='center',
    spacing=5,  # Will be auto-adjusted to fit labels if needed
    font_size=12
)

my_grid.save('individual_labels_grid.png')

Note: When using labels, the spacing between rows is automatically adjusted to be at least line_height * labels_max_lines to ensure labels don't overlap with images below them. Note how labels is the second parameter after images for convenient use!

Auto-sizing

from pillow-de import grid

# Auto-calculate grid dimensions (roughly square)
images = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg', 'img5.jpg']
my_grid = grid(images)  # Will create a 3x2 grid automatically

my_grid.save('auto_grid.png')

Features

  • Command-line tool: Create grids directly from the terminal
  • Automatic resizing: Images are automatically resized to fit uniformly in the grid
  • Flexible layouts: Specify rows and columns or let the package auto-calculate
  • Labels: Add column labels, row labels, and individual image labels
  • Customizable spacing: Control spacing between images
  • PIL-like interface: Familiar methods like save(), show(), copy(), etc.
  • Multiple input formats: Accept PIL Images or file paths

API Reference

Command-Line Interface

pillow-de [images...] -o OUTPUT [options]

Required Arguments:

  • images: Input image files (supports multiple files)
  • -o, --output: Output file path

Grid Layout:

  • --rows: Number of rows (auto-calculated if not specified)
  • --cols: Number of columns (auto-calculated if not specified)

Labels:

  • --labels: Comma-separated labels for each image, or path to .txt file (one label per line)
  • --x-labels: Comma-separated column labels, or path to .txt file (one label per line)
  • --y-labels: Comma-separated row labels, or path to .txt file (one label per line)

Label Styling:

  • --labels-align {left,center,right}: Image label alignment (default: center)
  • --x-labels-align {left,center,right}: Column label alignment (default: left)
  • --y-labels-align {left,center,right}: Row label alignment (default: left)
  • --labels-max-lines: Maximum lines for image labels (default: 1)
  • --x-labels-max-lines: Maximum lines for column labels (default: 2)
  • --y-labels-max-lines: Maximum lines for row labels (default: 2)

Styling:

  • --spacing: Spacing between images in pixels (default: 5)
  • --font-size: Font size for labels (default: 12)
  • --background-color: Background color (default: white)
  • --font-path: Path to custom font file

Other:

  • -v, --verbose: Verbose output
  • -h, --help: Show help message

Python API

Grid(images, labels=None, rows=None, cols=None, **kwargs)

Create a Grid object from a list of images.

Parameters:

  • images: List of PIL Image objects or file paths
  • labels: Optional list of labels for each individual image (positioned under each image)
  • rows: Number of rows (auto-calculated if not provided)
  • cols: Number of columns (auto-calculated if not provided)
  • x_labels: Optional list of labels for columns
  • y_labels: Optional list of labels for rows
  • spacing: Spacing between images in pixels (default: 5)
  • x_labels_max_lines: Maximum number of lines for x_labels (default: 2)
  • y_labels_max_lines: Maximum number of lines for y_labels (default: 2)
  • labels_max_lines: Maximum number of lines for labels (default: 1)
  • x_labels_align: Horizontal alignment for x_labels - 'left', 'center', 'right' (default: 'left')
  • y_labels_align: Horizontal alignment for y_labels - 'left', 'center', 'right' (default: 'left')
  • labels_align: Horizontal alignment for labels - 'left', 'center', 'right' (default: 'center')
  • font_size: Size of label font (default: 12)
  • background_color: Background color for the grid (default: "white")

Grid Methods

  • save(filename, **kwargs): Save the grid image to a file
  • show(): Display the grid image
  • copy(): Return a copy of the grid image
  • resize(size, resample): Resize the grid image

Grid Properties

  • size: Size of the grid image as (width, height)
  • width: Width of the grid image
  • height: Height of the grid image
  • mode: Color mode of the grid image

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pillow_de-1.0.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pillow_de-1.0.0-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

Details for the file pillow_de-1.0.0.tar.gz.

File metadata

  • Download URL: pillow_de-1.0.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pillow_de-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c3b9eb275cdbc92a30ad7dc229dd06d94eba730f0b94c6bdd67b3a5e150aaab9
MD5 a6f054e57c1193ba05ce79d7ffc86130
BLAKE2b-256 27f08300534a37c979283edfb54e929770957407707138aaa038465720f3bab3

See more details on using hashes here.

File details

Details for the file pillow_de-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pillow_de-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for pillow_de-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cde49c198170b6bf6547f2270e1334b5f3013baaff55e882de8b1095185dacc
MD5 90dfa05e609364bc50a84f714fc31ba1
BLAKE2b-256 4f7b49307932d7e43de63d9246c8612ce3d93c5298e282d4b3686d11980d1d67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page