Skip to main content

Swatcher

Swatcher is a Python module for generating Adobe ASE color swatches from images.

Background

Swatcher was born out of necessity in my day job as a Graphic Designer. 👨‍💻

Often, I need to extract exact color values from images for use in Adobe products and I just couldn't find a good way...

"Isn't there already software that samples colors from images?"

Yeah, there's a bunch, problem is, most are designed for sampling photographs and use algorithms that provide approximate color values. I typically sample computer generated graphics with fairly distinct colors, and I need exact values. 🎯

FYI, Swatcher works great on photographs too! 📸

Credit to Marcos Ojeda for his work on the Adobe ASE file writer. 👏

Installation

Install Swatcher with pip:

pip install swatcher

Usage

from swatcher import Swatcher

s = Swatcher('/path/to/your/image.jpg')

# view the most common colors (RGB values)
s.palette

Swatcher will automatically sample the provided image at initialization using the default settings max_colors=8 and sensitivity=75. I have found these general settings to work best for most images.

ℹ️ You can also specify max_colors and sensitivity at object creation.

s = Swatcher('/path/to/your/image.jpg', max_colors=5, sensitivity=125)

View the sampled swatches

To view the sample palette swatches in your default system image viewer.

s.show_palette_image()

Resample the image

If the sampled colors were not what you were expecting, you can easily resample your image with different settings.

s.sample(max_colors=4, sensitivity=50)
  • max_colors: Maximum number of colors to sample (may sample less)
  • sensitivity: How perceptively different (Euclidean Distance) a color must be from others to be included in the sampled palette. A lower value = more similar colors, a higher value = less similar colors.

Sensitivity Example:

If you have numerous grey values in your image, reducing the sensitivity will make sure you sample each individual grey. On the flip side, a landscape photograph with a lot of sky will probably sample too many blue values. Increasing the sensitivity will sample a more diverse palette with colors from more areas of the photograph.

Export an Adobe ASE swatch file

Once you have a palette you like, you can export it to an Adobe ASE swatch file for use in Adobe design products.

s.export_ase_file()

By default, the ASE swatch file will be saved in one of two places depending on how you initialized your Swatcher object.

  1. If you provided an image file path, the Adobe ASE swatch file will be saved in the same directory.
  2. If you provided a file object, the Adobe ASE swatch file will be saved in your current users home directory.

...or export to a specific location

s.export_ase_file("path/you/want/to/use/")

Resources

Metadata

Release files for swatcher 1.0.3

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

Source distribution (sdist)

Source distribution for swatcher 1.0.3
File Size Uploaded Provenance Actions
swatcher-1.0.3.tar.gz 11.0 kB Without provenance Details for swatcher-1.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 22.3 kB

Release files / swatcher-1.0.3.tar.gz

Download URL swatcher-1.0.3.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e3608c6fbba6b552d09d49918c71fa62ae1794d140f03a167809520ca0017aab
BLAKE2b-256 checksum
How to use checksums
01b0dd8870dda570e011cdcf665e089a97c84de63f0f3219096bc9c9d3f98740
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2

Release files / swatcher-1.0.3-py3-none-any.whl

Download URL swatcher-1.0.3-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c423979de8fb3c85e712576ff6b1ec37b2643eb2d046f2146b42ebc9bc694f7a
BLAKE2b-256 checksum
How to use checksums
d45a00632ace700c429e7a1153be02f380979546b7d6dc4219f10116a22503e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2

Security for swatcher 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files No provenance

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