Skip to content

Python Palette Extractor is a tool for extracting color palettes from images and generating a JSON format file with normal, light, and dark color palettes/schemes.

License

Notifications You must be signed in to change notification settings

AlTimofeyev/pypalex

Repository files navigation

PyPalEx

Python Palette Extractor

Package Example with Background Image by tsujin_bohboh on Twitter

PyPalEx is a tool for extracting color palettes from images and storing them in JSON / YAML formated files. This tool is intended to be OS independent, for use by the tech community for developing their own custom theme managers or by artists who want to extract color palettes for their art from images, pictures or wallpapers they adore.



TABLE OF CONTENTS



PYPALEX ARCHIVES


DEPENDENCIES

Aside from Python, the rest are Python packages that are installable with pip.

  • Python 3.6+
  • Pillow (PIL) 9.0+
    • For performing operations on images.
  • NumPy 1.21+
    • To manage large amounts of image data.
  • filetype 1.0+
    • To confirm filetypes are images file types.
  • PyYAML 5.4.1+
    • To manage YAML file types.

ENVIRONMENT VARIABLES

There are two optional environment variables that can be set by the user:

  • PYPALEX_CACHE_DIR
  • PYPALEX_CONFIG_DIR

By default, PyPalEx will try to store extracted color palettes into one of three locations:

  • PYPALEX_CONFIG_DIR
  • XDG_CONFIG_HOME/palex
  • $HOME/.config/palex

By default, PyPalEx will first try to save extracted color palettes wherever PYPALEX_CONFIG_DIR points to in the user's system. If the user does not set the PYPALEX_CONFIG_DIR environment variable, then PyPalEx will default to saving extracted color palettes wherever XDG_CONFIG_HOME/palex points to in the user's system. And if the XDG_CONFIG_HOME environment variable is not set, then PyPalEx will default to saving extracted color palettes into $HOME/.config/palex.
This default output location is, of course, overriden if PyPalEx is used with the -o --output option.


INSTALLATION

PIP INSTALL

System-wide install (sudo)

pip3 install pypalex

User install (No sudo)

pip3 install --user pypalex

# Add local 'pip' to PATH:
# (In your .bashrc, .zshrc etc)
export PATH="${PATH}:${HOME}/.local/bin/"

MANUAL/GIT INSTALL

git clone https://github.com/AlTimofeyev/pypalex
cd pypalex
pip3 install --user .

# Add local 'pip' to PATH:
# (In your .bashrc, .zshrc etc)
export PATH="${PATH}:${HOME}/.local/bin/"

USER GUIDE

DISCLOSURE

  • PyPalEx can only work on images that are in the RBG color space, so any images that you supply to PyPalEx that are not already in RGB will automatically be converted into RGB color space before the extraction process begins.
  • PyPalEx takes about ~5 seconds on average to process an image and extract color palettes.
  • When using PyPalEx on a directory of images, you can calculate the time it takes to process all the images by multiplying the number of images by 5 seconds.
    • Example: You have a directory of 20 images. So the time it will take to process all the images is
      20 x 5 = ~100 seconds

Some images may take 2-3 seconds to be processed while other images may take 4-5 seconds to be processed. But the average wait time for an image to be processed and for color palettes to be extracted is about ~5 seconds.

OPTIONS LIST

  • -f --files
    • Specify the absolute file path(s).
    • If used with -p --path option, you only need to specify the relative file path(s).
  • -p --path
    • Specify the path from where to use images.
    • Absolute path is preferred, but relative path can also be used.
  • -o --output
    • Specify the output path where to store the JSON color palette.
  • --save-check
    • Asks if the user wants to save the extracted color palettes.
  • --preview
    • Shows a preview of the extracted color palettes before saving.
  • --preview-check
    • Shows a preview of, and asks if the user wants to save, the extracted color palettes.
  • --pastel
    • Converts all color types into pastel.
  • --pastel-light
    • Converts light color type into pastel.
  • --pastel-normal
    • Converts normal color type into pastel.
  • --pastel-dark
    • Converts dark color type into pastel.
  • -r --raw-dump
    • Saves the raw extracted colors without organizing them into color palettes.
  • -g --gen-config
    • Generates a default configuration file.
  • -w --where
    • Prints where the default output locations of the configuration file and extracted color palattes are located.
    • This option will also let you know if these locations exist or not, as they are optional.
  • -v --version
    • Prints the PyPalEx version.

NOTES

  • When using PyPalEx, the use of either -f --files and/or -p --path is a MUST. Without either, or both of, these two options being specified, PyPalEx will not work.
  • PyPalEx will skip over any files that are not images.
  • Please note that all the --pastel and --sat_pref options only affect the 6 base colors (red, green, yellow, blue, magenta, cyan) and do NOT affect the background, foreground, black, and white colors.
  • Please note that the user can individually select which palette to convert to pastel (do not mistake palette for "color scheme/color theme"). For more details, please refer to the PyPalEx wiki homepage to identify which "color scheme/color theme" contains the palette you wish to convert to pastel.

OPTION USAGE EXAMPLES

For usage examples of each of the options provided, please read the Wiki Homepage :
https://github.com/AlTimofeyev/pypalex/wiki#option-usage-examples


FEEDBACK

Any and all feedback is greatly appreciated and welcomed! On the PyPalEx GitHub repository, there is a Discussion post that is available for each Release version of PyPalEx and open to everyone for any comments or feedback on the version of PyPalEx you are using.

About

Python Palette Extractor is a tool for extracting color palettes from images and generating a JSON format file with normal, light, and dark color palettes/schemes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages