Title: | Read, Inspect, Manipulate, and Save Color Swatch Files |
---|---|
Description: | There are numerous places to create and download color palettes. These are usually shared in Adobe swatch file formats of some kind. There is also often the need to use standard palettes developed within an organization to ensure that aesthetics are carried over into all projects and output. Now there is a way to read these swatch files in R and avoid transcribing or converting color values by hand or or with other programs. This package provides functions to read and inspect Adobe Color (ACO), Adobe Swatch Exchange (ASE), GIMP Palette (GPL), OpenOffice palette (SOC) files and KDE Palette ("colors") files. Detailed descriptions of Adobe Color and Swatch Exchange file formats as well as other swatch file formats can be found at <http://www.selapa.net/swatches/colors/fileformats.php>. |
Authors: | Bob Rudis [aut, cre] |
Maintainer: | Bob Rudis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.6.0 |
Built: | 2025-02-10 03:58:49 UTC |
Source: | https://github.com/hrbrmstr/swatches |
Add a named color to an ASE swatch object
add_color(ase_obj, name, model, color_vals, type)
add_color(ase_obj, name, model, color_vals, type)
ase_obj |
An ASE object created with |
name |
name of the color |
model |
one of " |
color_vals |
vector of color values associated with the chosen |
type |
one of " |
ase_obj
(invisibly)
create_ase() |> add_color( name = "RGB Red", model = "RGB", color_vals = as.vector(col2rgb("#FF0000")/255), type = "global" ) |> add_color( name = "RGB Yellow", model = "RGB", color_vals = as.vector(col2rgb("#FFFF00")/255), type = "global" ) |> ase_encode() |> writeBin(tempfile(fileext = ".ase"))
create_ase() |> add_color( name = "RGB Red", model = "RGB", color_vals = as.vector(col2rgb("#FF0000")/255), type = "global" ) |> add_color( name = "RGB Yellow", model = "RGB", color_vals = as.vector(col2rgb("#FFFF00")/255), type = "global" ) |> ase_encode() |> writeBin(tempfile(fileext = ".ase"))
Encode a built ASE object for output
ase_encode(data)
ase_encode(data)
data |
An ASE swatch object created by |
raw vector
create_ase() |> add_color( name = "RGB Red", model = "RGB", color_vals = as.vector(col2rgb("#FF0000")/255), type = "global" ) |> add_color( name = "RGB Yellow", model = "RGB", color_vals = as.vector(col2rgb("#FFFF00")/255), type = "global" ) |> ase_encode() |> writeBin(tempfile(fileext = ".ase"))
create_ase() |> add_color( name = "RGB Red", model = "RGB", color_vals = as.vector(col2rgb("#FF0000")/255), type = "global" ) |> add_color( name = "RGB Yellow", model = "RGB", color_vals = as.vector(col2rgb("#FFFF00")/255), type = "global" ) |> ase_encode() |> writeBin(tempfile(fileext = ".ase"))
Create an ASE object
create_ase()
create_ase()
a list
(invisibly) classed as ase
create_ase() |> add_color( name = "RGB Red", model = "RGB", color_vals = as.vector(col2rgb("#FF0000")/255), type = "global" ) |> add_color( name = "RGB Yellow", model = "RGB", color_vals = as.vector(col2rgb("#FFFF00")/255), type = "global" ) |> ase_encode() |> writeBin(tempfile(fileext = ".ase"))
create_ase() |> add_color( name = "RGB Red", model = "RGB", color_vals = as.vector(col2rgb("#FF0000")/255), type = "global" ) |> add_color( name = "RGB Yellow", model = "RGB", color_vals = as.vector(col2rgb("#FFFF00")/255), type = "global" ) |> ase_encode() |> writeBin(tempfile(fileext = ".ase"))
Convert a list of named, hexadecimal RBG colors into an ASE object
hex_to_ase(colors, type)
hex_to_ase(colors, type)
colors |
named vector of RBG hex colors |
type |
one of " |
ase
object
ase_temp <- tempfile(fileext = ".ase") on.exit(unlink(ase_temp)) github_url <- "https://github.com/picwellwisher12pk/en_us/raw/master/Swatches/Metal.ase" metal <- read_ase(github_url) hex_to_ase(metal, "global") |> ase_encode() |> writeBin(ase_temp) read_ase(ase_temp)
ase_temp <- tempfile(fileext = ".ase") on.exit(unlink(ase_temp)) github_url <- "https://github.com/picwellwisher12pk/en_us/raw/master/Swatches/Metal.ase" metal <- read_ase(github_url) hex_to_ase(metal, "global") |> ase_encode() |> writeBin(ase_temp) read_ase(ase_temp)
Given a path or URL to an .aco
file, this function will return
a named character vector (if color names are present) of hex RGB colors.
read_aco(path, use_names = TRUE, .verbose = FALSE)
read_aco(path, use_names = TRUE, .verbose = FALSE)
path |
partial or full file path or URL to an ACO file |
use_names |
add color names to the vector (defaults to |
.verbose |
show extra information about ACO file processing |
When using named color palettes in a ggplot2
scale_
context, you
must unname
, set use_names
to FALSE
or override their names
to map to your own factor levels.
# built-in palette eighties <- read_aco(system.file("palettes", "tomorrow_night_eighties.aco", package="swatches")) print(eighties) show_palette(eighties) # from the internet directly ## Not run: tomorrow_night <- read_aco("https://bit.ly/tomorrow-night-aco") print(tomorrow_night) show_palette(tomorrow_night) ## End(Not run)
# built-in palette eighties <- read_aco(system.file("palettes", "tomorrow_night_eighties.aco", package="swatches")) print(eighties) show_palette(eighties) # from the internet directly ## Not run: tomorrow_night <- read_aco("https://bit.ly/tomorrow-night-aco") print(tomorrow_night) show_palette(tomorrow_night) ## End(Not run)
Given a path or URL to an .ase
file, this function will return
a named character vector (if color names are present) of hex RGB colors.
read_ase(path, use_names = TRUE, .verbose = FALSE)
read_ase(path, use_names = TRUE, .verbose = FALSE)
path |
partial or full file path or URL to an ASE file |
use_names |
add color names to the vector (defaults to |
.verbose |
show extra information about ASE file processing |
When using named color palettes in a ggplot2
scale_
context, you
must unname
, set use_names
to FALSE
or override their names
to map to your own factor levels. Also, Neither Lab nor greyscale colors are supported.
# built-in palette keep_the_change <- read_ase(system.file("palettes", "keep_the_change.ase", package="swatches")) print(keep_the_change) show_palette(keep_the_change) # from the internet directly ## Not run: github_url <- "https://github.com/picwellwisher12pk/en_us/raw/master/Swatches/Metal.ase" metal <- read_ase(github_url) print(metal) show_palette(metal) ## End(Not run)
# built-in palette keep_the_change <- read_ase(system.file("palettes", "keep_the_change.ase", package="swatches")) print(keep_the_change) show_palette(keep_the_change) # from the internet directly ## Not run: github_url <- "https://github.com/picwellwisher12pk/en_us/raw/master/Swatches/Metal.ase" metal <- read_ase(github_url) print(metal) show_palette(metal) ## End(Not run)
Given a path or URL to an .gpl
file, this function will return
a named character vector (if color names are present) of hex RGB colors.
read_gpl(path, use_names = TRUE, .verbose = FALSE)
read_gpl(path, use_names = TRUE, .verbose = FALSE)
path |
partial or full file path or URL to a GPL file |
use_names |
add color names to the vector (defaults to |
.verbose |
show extra information about GPL file processing |
When using named color palettes in a ggplot2
scale_
context, you
must unname
, set use_names
to FALSE
or override their names
to map to your own factor levels. Also, Neither Lab nor greyscale colors are supported.
# built-in palette gimp16 <- read_gpl(system.file("palettes", "base16.gpl", package="swatches")) print(gimp16) show_palette(gimp16) # from the internet directly ## Not run: bright <- read_gpl(URL) print(bright) show_palette(bright) ## End(Not run)
# built-in palette gimp16 <- read_gpl(system.file("palettes", "base16.gpl", package="swatches")) print(gimp16) show_palette(gimp16) # from the internet directly ## Not run: bright <- read_gpl(URL) print(bright) show_palette(bright) ## End(Not run)
Given a path or URL to an .colors
file, this function will return
a named character vector (if color names are present) of hex RGB colors.
read_kde(path, use_names = TRUE, .verbose = FALSE)
read_kde(path, use_names = TRUE, .verbose = FALSE)
path |
partial or full file path or URL to a GPL file |
use_names |
add color names to the vector (defaults to |
.verbose |
show extra information about GPL file processing |
When using named color palettes in a ggplot2
scale_
context, you
must unname
, set use_names
to FALSE
or override their names
to map to your own factor levels.
# built-in palette fourty <- read_kde(system.file("palettes", "fourty.colors", package="swatches")) print(fourty) #show_palette(fourty) # show_palette(bright)
# built-in palette fourty <- read_kde(system.file("palettes", "fourty.colors", package="swatches")) print(fourty) #show_palette(fourty) # show_palette(bright)
Given a path or URL to an palette file, this function will attempt to determine which palette file format to read by the file type and return a named character vector (if color names are present) of hex RGB colors.
read_palette(path, use_names = TRUE, .verbose = FALSE)
read_palette(path, use_names = TRUE, .verbose = FALSE)
path |
partial or full file path or URL to a GPL file |
use_names |
add color names to the vector (defaults to |
.verbose |
show extra information about GPL file processing |
When using named color palettes in a ggplot2
scale_
context, you
must unname
, set use_names
to FALSE
or override their names
to map to your own factor levels.
Given a path or URL to an .soc
file, this function will return
a named character vector (if color names are present) of hex RGB colors.
read_soc(path, use_names = TRUE, .verbose = FALSE)
read_soc(path, use_names = TRUE, .verbose = FALSE)
path |
partial or full file path or URL to a GPL file |
use_names |
add color names to the vector (defaults to |
.verbose |
show extra information about GPL file processing |
When using named color palettes in a ggplot2
scale_
context, you
must unname
, set use_names
to FALSE
or override their names
to map to your own factor levels.
# built-in palette soc_file <- system.file("palettes", "ccooo.soc", package="swatches") system(sprintf("cat %s", soc_file)) ccooo <- read_soc(soc_file) print(ccooo) show_palette(ccooo) # from the internet directly ## Not run: galaxy <- read_soc("https://www.openoffice.org/ui/VisualDesign/docs/colors/galaxy.soc") print(galaxy) show_palette(galaxy) ## End(Not run)
# built-in palette soc_file <- system.file("palettes", "ccooo.soc", package="swatches") system(sprintf("cat %s", soc_file)) ccooo <- read_soc(soc_file) print(ccooo) show_palette(ccooo) # from the internet directly ## Not run: galaxy <- read_soc("https://www.openoffice.org/ui/VisualDesign/docs/colors/galaxy.soc") print(galaxy) show_palette(galaxy) ## End(Not run)
Given a character vector (hex RGB values), display palette in graphics window.
show_palette(palette)
show_palette(palette)
palette |
vector of character hex RGB values |
# built-in palette keep_the_change <- read_ase(system.file("palettes", "keep_the_change.ase", package="swatches")) print(keep_the_change) # show_palette(keep_the_change)
# built-in palette keep_the_change <- read_ase(system.file("palettes", "keep_the_change.ase", package="swatches")) print(keep_the_change) # show_palette(keep_the_change)
Given a palette and a desired number of colors to use, this function will compute CIEDE2000 and attempt to reduce the input set to a disctinct smaller set of colors based on color distances.
trim_palette(pal, n = 5)
trim_palette(pal, n = 5)
pal |
input palette to reduct |
n |
number of desired colors |
vector of n
colors from pal
internal CIEDE2000 color distance implementation by Gaurav Sharma & Maynard P Baalthazar