Description Usage Arguments Examples
View source: R/extract_colours.R
This function downloads an image and extracts the dominant colours from it. The code is based on dsparks' gist (https://gist.github.com/dsparks/3980277).
1 2 | extract_colours(url_img = "http://developer.r-project.org/Logo/Rlogo-1.png",
num_col = 5, rsize = 100)
|
url_img |
URL of the image (can be PNG, JPG, JPEG, TIFF) or a local file. Can also
be an |
num_col |
Number of dominant colours to be extracted (default = 5) |
rsize |
Size to reduce original image to, for further processing. This is the size, in pixels, for the largest dimension, from which colours are extracted. Please be careful with this option, as setting it too high can result in an extremely large processing time (or even running out of physical memory). |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #Example 1a - Using the R logo to create a 5-colour palette
pal_r <- extract_colours("http://developer.r-project.org/Logo/Rlogo-1.png")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_r, main = "Palette based on R Logo")
hist(Nile, breaks = 5, col = pal_r, main = "Palette based on R Logo")
#Example 1b - Using the Kill Bill poster to create a 5-colour palette
pal_kb <- extract_colours("http://www.moviegoods.com/Assets/product_images/1010/477803.1010.A.jpg")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_kb, main = "Palette based on Kill Bill")
hist(Nile, breaks = 5, col = pal_kb, main = "Palette based on Kill Bill")
#Example 1c - Using Homer Simpson
pal_s <- extract_colours("http://haphappy.com/wp-content/uploads/2011/03/homerbeer2.png")
par(mfrow = c(1,2))
pie(rep(1, 5), col = pal_s, main = "Palette based on Simpsons")
hist(Nile, breaks = 5, col = pal_s, main = "Palette based on Simpsons")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.