Skip to main content

Generate Adobe ASE swatches from images.

Project description

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

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

swatcher-1.0.3.tar.gz (11.0 kB view hashes)

Uploaded Source

Built Distribution

swatcher-1.0.3-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

Supported by

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