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 repetitions of each color in the row, the third is the total number of rows. The function returns an image which you can save using FileIO's save()
:
using FileIO, ColorSchemeTools, Images, Colors
img = colorscheme_to_image(ColorSchemes.vermeer, 150, 20)
save("/tmp/cs_vermeer-150-20.png", img)
The image_to_swatch()
function extracts a colorscheme from the image in and saves it as a swatch in a PNG.
image_to_swatch("/tmp/input.png", 10, "/tmp/output.png")
ColorSchemeTools.colorscheme_to_image
— Function.colorscheme_to_image(cs, nrows=50, tilewidth=5)
Make an image from a colorscheme by repeating the colors in a colorscheme.
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_swatch
— Function.image_to_swatch(imagefilepath, samples, destinationpath; nrows=50, tilewidth=5)
Extract a colorscheme 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 text file with the imaginatively-titled colorscheme_to_text()
function.
Remember to make the name a Julia-friendly one, because it will become a symbol and a dictionary key.
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_text
— Function.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")