Select colours from an image in R with {eyedroppeR}

There are fancy ways to extract colours from images but sometimes it’s easier if you could simply click on the image and choose the colours you want.

With eyedroppeR you can click on the image and it will return the hex codes of the selected pixel all within R.

Installation

Install from GitHub.

devtools::install_github("doehm/eyedroppeR")

For more info follow the link to the GitHub repo.

Usage

Use eyedropper with the following steps:

Find the image you want to pick colours from online. Local images can be used as well.

Right-click and ‘copy image address’. As an example copy the following image (right-click > copy image address).

Choose how many colours to pick e.g. n = 8.

Run eyedropper(n = 8, img_path = '<paste address here>', label = "Sunset on the South Coast").

Click the 8 desired colours. You can click on either the image itself or the swatch at the bottom. The image will be stretched to the borders of the window, but that’s OK.

Done! Copy the returned string and add it to your script and start using pal.

The palette, the image that is saved at the temporary address and the label will also be returned by the function. It will also output to the console a message that can be copied and pasted directly to your code. That’s the best part!

Automatically extract a palette with extract_pal()

To speed up the process and if you’re not looking for specific colours you can run extract_pal to automatically select some for you.

library(eyedroppeR)

path <- 'https://github.com/doehm/eyedroppeR/blob/main/dev/images/belize.jpg?raw=true'
extract_pal(12, path, label = "Caye Caulker, Belize", sort = "auto")
caye_caulker_belize <- c('#477d7c', '#4f967e', '#a1d6f5', '#cbe8f4', '#f0e4c6', '#d8c09c', '#adae46', '#a6954f', '#e14f16', '#a92613', '#cf4959', '#d78462')

$label
[1] "Caye Caulker, Belize"

$pal
 [1] "#477d7c" "#4f967e" "#a1d6f5" "#cbe8f4" "#f0e4c6" "#d8c09c" "#adae46" "#a6954f" "#e14f16" "#a92613"
[11] "#cf4959" "#d78462"

$img_path
[1] "C:\\Users\\Dan\\AppData\\Local\\Temp\\RtmpIN1NcN\\file70302f63b83"

Often you won’t quite get what you’re after and you’ll want to use eyedropper instead.

Other functions

  • sort_pal: allows you to manually sort a palette by clicking on the colours in order. It also allows you to select a specified number of colours if you don’t want them all.
  • show_pal : Simple helper to display the palette.
Follow me on social media: