# Saving colorschemes

## Saving colorschemes as images

Sometimes you want to save a colorscheme, which is usually just a pixel thick, as a swatch or image. You can do this with colorscheme_to_image(). The second argument is the number of rows. The third argument is the number of times each pixel is repeated in the row. The function returns an image which you can save using FileIO's save():

using FileIO, ColorSchemeTools, Images, Colors

# 20 pixels for each color, 150 rows
img = colorscheme_to_image(ColorSchemes.vermeer, 150, 20)

save("/tmp/cs_vermeer-150-20.png", img)

The image_to_swatch() function (a shortcut) extracts a n-color scheme from a supplied image and saves it as a swatch in a PNG.

image_to_swatch("/tmp/input.png", 10, "/tmp/output.png")
ColorSchemeTools.colorscheme_to_imageFunction
colorscheme_to_image(cs, nrows=50, tilewidth=5)

Make an image from a ColorScheme by repeating the colors in nrows rows, repeating each pixel tilewidth times.

Returns the image as an array.

Examples:

using FileIO

img = colorscheme_to_image(ColorSchemes.leonardo, 50, 200)
save("/tmp/cs_image.png", img)

save("/tmp/blackbody.png", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))
ColorSchemeTools.image_to_swatchFunction
image_to_swatch(imagefilepath, samples, destinationpath;
nrows=50,
tilewidth=5)

Extract a ColorsSheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.

Specify the number of colors. You can also specify the number of rows, and how many times each color is repeated.

image_to_swatch("monalisa.jpg", 10, "/tmp/monalisaswatch.png")

## Saving colorschemes to text files

You can save a ColorScheme as a (Julia) text file with the imaginatively-titled colorscheme_to_text() function.

Remember to make the name a Julia-friendly one, because it may eventually become a symbol and a dictionary key if the Julia file is include-d.

colorscheme_to_text(ColorSchemes.vermeer,
"the_lost_vermeer",           # name
"/tmp/the_lost_vermeer.jl",   # filename
category="dutch painters",    # category
notes="it's not really lost"  # notes
)

Of course, if you just want the color definitions, you can simply type:

map(println, ColorSchemes.vermeer.colors);
ColorSchemeTools.colorscheme_to_textFunction
colorscheme_to_text(cscheme::ColorScheme, schemename, filename;
category="dutch painters",   # category
notes="it's not really lost" # notes
)

Write a ColorScheme to a Julia text file.

Example

colorscheme_to_text(ColorSchemes.vermeer,
"the_lost_vermeer",          # name
"/tmp/the_lost_vermeer.jl",  # file
category="dutch painters",   # category
notes="it's not really lost" # notes
)

and read it back in with:

include("/tmp/the_lost_vermeer.jl")