Skip to main content

Python tools for generating patterns and manipulating images

Project description

pyctorial

pip install pyctorial

pyctorial is a Python library for generating patterns and manipulating images. It provides tools for:

  • Generative gradients
  • Halftone rendering (bitmap and vector)
  • Image slicing
  • Gradient stretching
  • Programmatic image pipelines

It is designed to work both:

  • Inside Python scripts
  • Directly from the command line

The library focuses on a simple functional API where most operations:

  • take a PIL.Image
  • return a new PIL.Image

This makes it easy to compose multiple operations together.


Installation

pip install pyctorial

For development:

git clone https://github.com/decentishdev/pyctorial
cd pyctorial
pip install -e .

Quick Example

import pyctorial as px

img = px.load("photo.jpg")

dots = px.halftone(img)

px.save(dots, "halftone.png")

Command Line Example

pyctorial halftone photo.jpg dots.png

Philosophy

Most functions follow a simple pattern:

Image -> transform -> Image

This allows composable pipelines:

import pyctorial as px

img = px.load("portrait.jpg")

img = px.halftone(img)
img = px.gradient_stretch(img, x_start=400)

px.save(img, "result.png")

Core API

Image IO

These functions allow loading and saving images.

Load Image

import pyctorial as px

img = px.load("input.png")

Optional mode conversion:

img = px.load("photo.jpg", mode="L")

Save Image

px.save(img, "output.png")
px.save_svg(svg_str, "output.svg")

Filters

Filters modify an existing image.


Halftone Filter

Creates a dot halftone effect similar to old print media.

Python Usage

import pyctorial as px

img = px.load("portrait.jpg")

dots = px.halftone(
    img,
    cell_size=12,
    max_dot_ratio=0.9
)

px.save(dots, "dots.png")

Parameters

Parameter Description
cell_size Size of the halftone grid
max_dot_ratio Maximum dot size relative to cell
invert Invert brightness mapping

Example

dots = px.halftone(img, cell_size=8)

Vector Halftone (SVG)

Generates a vector halftone that scales infinitely.

Returns an SVG string.

Python Example

svg = px.halftone_svg(img)

px.save_svg(svg)

Example with parameters

svg = px.halftone_svg(
    img,
    cell_size=10,
    max_dot_ratio=0.8
)

Pattern Generation

Pattern generators create new images from scratch.


Noisy Gradient

Creates a blurred, warped, generative gradient.

This gradient uses:

  • focal color points
  • gaussian blur
  • Perlin noise warping
  • film grain

Python Example

import pyctorial as px

img = px.noisy_gradient(
    width=1200,
    height=800,
    num_focal_points=6
)

px.save(img, "gradient.png")

Parameters

Parameter Description
width Output width
height Output height
num_focal_points Number of color sources
blur_strength Amount of gradient blur
warp_strength Strength of noise distortion

Example

img = px.noisy_gradient(
    2000,
    2000,
    num_focal_points=10,
    blur_strength=300
)

Transforms

Transforms reshape an image spatially.


Slice

Splits an image into vertical slices.

Python Example

import pyctorial as px

img = px.load("image.png")

slices = px.slice(img, slices=8)

for i, s in enumerate(slices):
    px.save(s, f"slice_{i}.png")

Parameters

Parameter Description
slices Number of vertical slices

Gradient Stretch

Expands an image horizontally by interpolating columns.

Useful for generative distortions.

Python Example

img = px.load("gradient.png")

stretch = px.gradient_stretch(
    img,
    x_start=300,
    width_multiplier=2.0
)

px.save(stretch, "stretched.png")

Parameters

Parameter Description
x_start Column where stretching begins
width_multiplier How much to expand width
base_spacing Initial anchor spacing
growth_base Exponential growth factor
max_anchors Maximum anchor points

Command Line Interface

pyctorial includes a command line tool.

pyctorial COMMAND [OPTIONS]

CLI: Halftone

pyctorial halftone input.jpg output.png

Options:

--cell-size 10
--max-dot-ratio 0.8
--invert

Example:

pyctorial halftone photo.jpg dots.png --cell-size 8

CLI: Halftone SVG

pyctorial halftone-svg input.jpg output.svg

Example:

pyctorial halftone-svg portrait.jpg halftone.svg

CLI: Noisy Gradient

pyctorial noisy-gradient output.png

Example:

pyctorial noisy-gradient gradient.png \
    --width 2000 \
    --height 2000 \
    --focal-points 8

CLI: Slice

pyctorial slice input.png output_directory --slices 12

Example:

pyctorial slice image.png slices/ --slices 10

CLI: Gradient Stretch

pyctorial gradient-stretch input.png output.png --x-start 400

Example:

pyctorial gradient-stretch gradient.png stretched.png \
    --x-start 300 \
    --width-multiplier 3

Example Pipelines

Halftone a Generated Gradient

import pyctorial as px

img = px.noisy_gradient(1200, 800, 6)

img = px.halftone(img)

px.save(img, "gradient_halftone.png")

Generate Multiple Gradients

import pyctorial as px

for i in range(10):

    img = px.noisy_gradient(1200, 800, 6)

    px.save(img, f"gradient_{i}.png")

Gradient Stretch Art

import pyctorial as px

img = px.load("gradient.png")

img = px.gradient_stretch(img, x_start=500)

px.save(img, "abstract.png")

Module Structure

pyctorial
├── filters
│   └── halftone
│
├── generate
│   └── noisy_gradient
│
├── transforms
│   ├── slice
│   └── gradient_stretch
│
├── io
│
└── cli

Dependencies

pyctorial relies on several libraries:

  • Pillow
  • NumPy
  • noise
  • scipy
  • tqdm

These will automatically install with pip.


Contributing

Contributions are welcome.

Possible areas:

  • new pattern generators
  • image filters
  • geometric distortions
  • color tools
  • GPU acceleration

License

MIT License


Future Ideas

Possible future features:

  • Voronoi patterns
  • Flow fields
  • Reaction diffusion textures
  • Fractal noise generators
  • Tiling generators
  • Image dithering
  • Color palette utilities
  • Node-based pipelines

Summary

pyctorial is intended as a lightweight generative image toolkit combining:

  • procedural pattern generation
  • image filters
  • spatial transforms
  • CLI utilities

It is ideal for:

  • generative art
  • image experimentation
  • creative coding
  • automated graphics pipelines

Enjoy creating with pyctorial.

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

pyctorial-0.1.3.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

pyctorial-0.1.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file pyctorial-0.1.3.tar.gz.

File metadata

  • Download URL: pyctorial-0.1.3.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pyctorial-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0b4808a19da339b5d4690466cf8e4addbe66f41cb07d6afc3b91426a51baca0a
MD5 7a747f0591fa0e1dc190d237e31b9860
BLAKE2b-256 a326cdf37ac7aabf2b3f7323778aef420b25f79936b7973aa4c50aeb8a29e470

See more details on using hashes here.

File details

Details for the file pyctorial-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyctorial-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pyctorial-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 38b3acef36f74bf65d59fbe84fd9012a9b26a4ff86b34116f1f4de464e77479d
MD5 06140e1ea4d13da11922f59ccb270b36
BLAKE2b-256 293c9a790acae63ce505172608b5779e58b790d924f9a060f8471e6d65d0b2dd

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