Skip to main content

PyPi version PyPI - Python Version CircleCI Coveralls Codacy branch grade

Normal Catppuccin Macchiato Dracula Gruvbox

Match the colors of an image to a palette

Installation

pip install palettipy

Example

example.py

import os
import sys
import time

from PIL import Image

from palettipy import palettes_loader, palettipy_image
from palettipy.palette import Palette


def main(args: list[str], palettes_path: str = "palettes"):
    if len(args) <= 0 or len(args) >= 3:
        print("Usage: example.py path/to/image [palette name]")
        sys.exit(1)

    print(args)

    image_path = args[0]
    if not os.path.exists(image_path):
        print(f'Image "{image_path}" does not exist')
        sys.exit(1)

    palettes = palettes_loader.load_palettes(palettes_path)

    palette_name = palettes[0].name
    if len(args) > 1:
        palette_name = args[1]
        if palette_name not in [_p.name for _p in palettes]:
            print(f'Palette "{palette_name}" does not exist')
            sys.exit(1)

    start = time.time()

    palette: Palette = list(filter(lambda p: (p.name == palette_name), palettes))[0]
    image = Image.open(image_path)

    image_result = Image.fromarray(palettipy_image(palette, image))
    image_result.save("output.png")

    palette.log(f"Done in {(time.time() - start):.3f}s")
    sys.exit(0)


if __name__ == "__main__":
    main(sys.argv[1:])
python example.py path/to/image "Catppuccin Mocha"

Adding a palette

Single

To add a new palette, simply create a file in palettes directory like below

Rainbow.txt

#ff6b6b
#ffd93d
#6bcb77
#4d96ff

Variants

If you have multiple variants of a palette, just create a subfolder under palettes with all its variants in it

Rainbow/Pastel.txt

#ff6b6b
#ffd93d
#6bcb77
#4d96ff

Metadata

Release files for palettipy 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for palettipy 0.0.1
File Size Uploaded
palettipy-0.0.1.tar.gz 13.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for palettipy 0.0.1
File Interpreter ABI Platform
palettipy-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 MB

Release files / palettipy-0.0.1.tar.gz

Download URL palettipy-0.0.1.tar.gz
Size 13.7 MB
Tags Source
SHA-256 checksum
How to use checksums
4e660a1fa7ef324eb2df34a6c395faf64e266ea84e3594b28405da5bd2323b9a
BLAKE2b-256 checksum
How to use checksums
ebbcccef7d51cfe66a69171dcae5625ece568c553fa0b5370d7c0bb609804f1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release files / palettipy-0.0.1-py3-none-any.whl

Download URL palettipy-0.0.1-py3-none-any.whl
Size 9.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
330adf518811ea0599902832ae1ebdf16bfb2a028546e3cf80bfb81a468742a6
BLAKE2b-256 checksum
How to use checksums
54959e3d7809a88b0022a614816dedb971774983480d2fb53508c45a2d150cfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.8

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page