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 an image to return the hex codes of the selected pixels all within R.

Installation

Install from GitHub.

devtools::install_github("doehm/eyedroppeR")

You may also need to install ggchicklet

install.packages("ggchicklet", repos = "https://cinc.rud.is")

For more info follow the link to the GitHub repo.

Usage

Use eyedropper with the following steps:

  1. Find the image you want to pick colours from online.
  2. Right-click and ‘copy image address’.
    • As an example use the image below (right-click > copy image address). 
  3. Choose how many colours to pick e.g. n = 5.
  4. Run pal <- eyedropper(n = 5).
    • eyedropper will read the copied address from the clipboard if img_path is left as NULL
    • If you have a local file or a saved path you can reference it directly with 
      pal <- eyedropper(n = 5, img_path = path)
  5. Click the 5 desired colours. The image will be stretched to the borders of the window, but that’s OK.
  6. Done! Copy the returned string and add it to your script and start using pal.

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.
  • extract_pal: automatically selects a specified number of colours using a clustering algorithm. It will read the image path from the clipboard as well and allow you to sort the colours after they are extracted.
  • show_pal : Simple helper to display the palette.
Follow me on social media: