palette_generator package

summary

palette_generator.convert_colors

Tools for converting between color spaces.

palette_generator.extract_colors

Extract a finite number of representative colors from an image.

palette_generator.make_theme

Create a 12-color theme from a pre-computed palette.

palette_generator.gen_palette

Generate a palette image from a base image and set of colors.

palette_generator.convert_colors module

Tools for converting between color spaces.

Functions:
palette_generator.convert_colors.cieluv_to_hex(luv: Tuple[float, float, float]) str

Convert CIE-LUV space to hexadecimal code.

Parameters

luv (Tuple[float, float, float]) – CIE-LUV space

Returns

hexadecimal code

Return type

str

palette_generator.convert_colors.cieluv_to_xyz(luv: Tuple[float, float, float]) Tuple[float, float, float]

Convert CIE-LUV space to XYZ space.

Parameters

luv (Tuple[float, float, float]) – CIE-LUV space

Returns

XYZ space

Return type

Tuple[float, float, float]

palette_generator.convert_colors.hex_to_everything(hex_series: pandas.core.series.Series) pandas.core.frame.DataFrame

Convert many hexadecimal codes to all available color spaces.

Parameters

hex_series (pd.Series) – many hexadecimal codes

Returns

all color spaces in columns,

with same index as hex_series

Return type

pd.DataFrame

palette_generator.convert_colors.hex_to_rgb(hex_code: str) Tuple[int, int, int]

Convert hexadecimal code to RGB space.

Parameters

hex_code (str) – hexadecimal

Returns

RGB

Return type

Tuple[int, int, int]

palette_generator.convert_colors.rgb_to_hex(rgb: Tuple[int, int, int]) str

Convert RGB space to hexadecimal code.

Parameters

rgb (Tuple[int, int, int]) – RGB space

Returns

hexadecimal code

Return type

str

palette_generator.convert_colors.rgb_to_hsv(rgb: Tuple[int, int, int]) Tuple[float, float, float]

Convert RGB space to HSV space.

Parameters

rgb (Tuple[int, int, int]) – RGB space

Returns

HSV space

Return type

Tuple[float, float, float]

palette_generator.convert_colors.rgb_to_xyz(rgb: Tuple[int, int, int]) Tuple[float, float, float]

Convert RGB space to XYZ space.

Parameters

rgb (Tuple[int, int, int]) – RGB space

Returns

XYZ space

Return type

Tuple[float, float, float]

palette_generator.convert_colors.xyz_to_cieluv(xyz: Tuple[float, float, float]) Tuple[float, float, float]

Convert XYZ space to CIE-LUV space.

Parameters

xyz (Tuple[float, float, float]) – XYZ space

Returns

CIE-LUV space

Return type

Tuple[float, float, float]

palette_generator.convert_colors.xyz_to_rgb(xyz: Tuple[float, float, float]) Tuple[int, int, int]

Convert XYZ space to RGB space.

Parameters

xyz (Tuple[float, float, float]) – XYZ space

Returns

RGB space

Return type

Tuple[int, int, int]

palette_generator.extract_colors module

Extract a finite number of representative colors from an image.

Functions:
  • main(): extract colors from an image using CLI-style args

  • make_parser(): create the CLI parser

palette_generator.extract_colors.main(img_path: str, n_colors: int = 512, hist_file: str = 'color_hist.txt', **kwargs)

Extract colors from an image.

Parameters
  • img_path (str) – image file

  • n_colors (int) – number of colors to extract; default: 512

  • hist_file (str) – save counts and hex codes to this file; default: ‘color_hist.txt’

Gobbles additional kwargs.

palette_generator.extract_colors.make_parser(parser: Optional[argparse.ArgumentParser] = None) argparse.ArgumentParser

Create a CLI parser.

Parameters

parser (argparse.ArgumentParser) – pre-existing parser to modify; default: None

Returns

argument parser

Return type

argparse.ArgumentParser

palette_generator.gen_palette module

Generate a palette image from a base image and set of colors.

functions:
classes:
  • Palette: visual palette created on an image base

class palette_generator.gen_palette.Palette(img_path: str, **kwargs)

Bases: object

Visual palette created on an image base.

Overlay color samples on image across the left and right of the image. If the input is provided in ‘.json’ format, also label the hex codes with the names provided by the ‘.json’. If ‘fg’ and/or ‘bg’ are provided, they will be used as the text color for the labels.

Parameters
  • img_path (str) – path to image

  • color_file (str) – path to color file; default: ‘colors.json’

  • palette_file (str) – path to saved image; default: ‘palette.png’

  • cheight (int) – height (in pixels) of a color swatch; default: 90

  • cwidth (int) – width (in pixels) of a color swatch; default: 180

  • cwidth – margin (in pixels) between color swatches, also used for corner radius; default: 10

  • font_family (str) – font to use; default: ‘Sarabun’ else system default

  • font_size (int) – font size for text; default: 28

cheight

height (in pixels) of a color swatch

cmargin

margin (in pixels) between color swatches, also used for radius

cwidth

width (in pixels) of a color swatch

palette_file

path to saved image

save(fname: Optional[str] = None)

Save the palette to image file.

Parameters

fname (str) – path to save; default: palette_file

show()

Not Implemented.

palette_generator.gen_palette.main(args: argparse.Namespace)

Generate a visual palette from CLI-like arguments.

Parameters

args (argparse.Namespace) – arguments from CLI

palette_generator.gen_palette.make_parser(parser: Optional[argparse.ArgumentParser] = None) argparse.ArgumentParser

Make a CLI-based argument parser.

Parameters

parser (argparse.ArgumentParser) – pre-existing parser to modify; default: None

Returns

Return type

argparse.ArgumentParser

palette_generator.make_theme module

Create a 12-color theme from a pre-computed palette.

Classes:
  • Themer: make a color theme from a palette

Functions:
class palette_generator.make_theme.Themer(fname: str = 'color_hist.txt', p_mix: float = 0.25)

Bases: object

Make a color theme.

Parameters
  • fname (str) – color histogram file; default: ‘color_hist.txt’

  • p_mix (float) – percent to mix pure colors in with histogram colors; default: 0.25

colors

colors loaded from fname

p_mix

amount to mix pure colors with image colors

plot(mode: str = 'LUV', scale: float = 30.0)

Plot the palette’s colors, weighted by size.

Parameters
  • mode (3-len str or iterable) – which color space to use; default: ‘LUV’

  • scale (float) – Degree by which to scale point size; default: 30.

save(fname: str = 'colors.json')

Save the theme to file.

Can save in json format or text/csv format.

Parameters

fname (str) – save path; will save in json format if fname ends with ‘.json’, else in csv format; default: ‘colors.json’

property theme: pandas.core.series.Series

Calculate and return the best-calculated theme for the palette.

Returns

hex codes for each theme color

Return type

pd.Series

palette_generator.make_theme.main(args: argparse.Namespace)

Execute the palette_generator.make_theme script.

Creates theme and saves it to file.

Parameters

args (argparse.Namespace) – arguments from running script in CLI

palette_generator.make_theme.make_parser(parser: Optional[argparse.ArgumentParser] = None) argparse.ArgumentParser

Create a CLI parser.

Parameters

parser (argparse.ArgumentParser) – pre-existing parser to modify; default: None

Returns

argument parser

Return type

argparse.ArgumentParser