Skip to main content

Pure-Python, zero-dependency image library: codecs (PNG/JPEG/GIF/BMP/QOI/TIFF/APNG/...), processing, drawing, QR/barcodes (encode+decode), feature detection, color science, and generative art — all from scratch

Project description

purepix

A pure-Python, zero-dependency image library — codecs, processing, drawing, and a pile of generative art, all implemented from scratch on top of the standard library. No NumPy, no Pillow, no C extensions.

import purepix
img = purepix.open("photo.jpg")          # auto-detected by magic bytes
small = img.resize((320, 240), purepix.BILINEAR)
purepix.save(small.filter(purepix.filters.SHARPEN), "out.png")

Install

pip install purepix

Requires Python 3.10+. Zero runtime dependencies.

What's inside

Image formats (read/write unless noted)

  • BMP, PNG (1/2/4/8/16-bit, Adam7 interlace, tRNS, lossless 16-bit), GIF (incl. animated), PNM (PPM/PGM), TGA (RLE), ICO, farbfeld, WBMP, PCX, XPM
  • JPEG — baseline and progressive decode + baseline encode
  • QOI — lossless, full round-trip
  • TIFF — LE/BE, none / PackBits / LZW / DEFLATE, multi-strip, multi-page
  • APNG — animated PNG read/write (offset, blend & dispose ops)
  • Compression written from scratch: DEFLATE (dynamic Huffman, greedy + lazy matching), GIF LZW, TIFF LZW, PackBits

Core image ops (Image)

  • 8-bit and 16-bit depth, mode conversion, crop, paste, split/merge channels
  • resize (nearest / bilinear), flip, rotate (90° and arbitrary angle), affine
  • point LUTs, convolution filter

Processing

  • filters — blur / gaussian / sharpen / unsharp / median / edge / sobel / emboss, brightness / contrast / gamma / invert / threshold / posterize / solarize, histogram / equalize / autocontrast, ordered dithering
  • color — RGB↔HSV, hue/saturation/value, sepia; CIELAB / LCh, ΔE (CIE76 & CIEDE2000), tone curves, vibrance, color temperature, gray-world white balance, levels
  • composite — blend modes, alpha compositing, linear/radial gradients
  • quantize — median-cut + Floyd–Steinberg dithering
  • morphology — erode/dilate/open/close, connected components
  • features — Canny edges, Hough lines/circles, Harris corners, contour tracing
  • effects — pixelate, vignette, motion blur, cartoon, glitch, oil paint
  • seam — content-aware resize (seam carving)
  • compare — aHash/dHash/pHash, PSNR, SSIM

Drawing (Draw)

  • point, line, wide/anti-aliased line, rectangle, rounded rectangle, ellipse, arc, polygon (scanline fill), Bézier & Catmull-Rom curves, flood fill, and text via a built-in bitmap font

Tools

  • qr — QR code generator and decoder (Reed–Solomon encode/decode, masking, format info)
  • barcode — Code 128 and EAN-13, encode and decode
  • stego — LSB steganography
  • exif — JPEG EXIF / PNG text metadata, auto-orient
  • dft — 2-D DFT: spectrum + low/high-pass filtering
  • ascii_art — render images to ASCII / ANSI

Generative art & simulation

  • fractal (Mandelbrot/Julia), noise (Perlin/fBm, clouds, marble), lsystem, reaction (Gray-Scott), automata (Life + elementary CA), maze, wfc, raytrace, plasma/fire, dla, voronoi/stippling, flowfield, sortviz, astar

Command line

python -m purepix info photo.png
python -m purepix convert in.png out.jpg --quality 90
python -m purepix resize in.png out.png --size 320x240
python -m purepix qr "https://example.com" qr.png
python -m purepix hash photo.png --type phash

Example

import purepix
from purepix import Draw, fractal, qr

# generate a fractal
fractal.mandelbrot((400, 300), max_iter=150).save("mandelbrot.png")

# draw with the built-in font
img = purepix.Image.new("RGB", (200, 60), (20, 20, 30))
Draw(img).text((10, 20), "PUREPIX", (0, 255, 180), scale=3)
img.save("banner.png")

# make a QR code
qr.encode("hello world", ec="M").save("qr.png")

License

MIT © Equinox

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

purepix-0.2.0.tar.gz (131.3 kB view details)

Uploaded Source

Built Distribution

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

purepix-0.2.0-py3-none-any.whl (116.1 kB view details)

Uploaded Python 3

File details

Details for the file purepix-0.2.0.tar.gz.

File metadata

  • Download URL: purepix-0.2.0.tar.gz
  • Upload date:
  • Size: 131.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for purepix-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f68a28b5fb478943070fe7861282fac41e1d096a6d22a81ae82b675fedd471dc
MD5 34d327240238dc5bbd2d50886f5ef3ee
BLAKE2b-256 5e2c33d0fb0d3c5577290fea25dd5dcf871c15ea1b4f2cf3683fcdf86e79947f

See more details on using hashes here.

File details

Details for the file purepix-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: purepix-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 116.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for purepix-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c716a417980d74df2a22ec306d1ebb8dfacdadbc7a26e286a9bf6e292c30e3fd
MD5 ae8c8d145c81fef50c5b7244a8b94802
BLAKE2b-256 3aa44403afe4cd0de2bafaa6698162323878b6b3af6e8a006c108efd3e8dc5b0

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