R/rijkspalette.R

Defines functions rijksPalette

Documented in rijksPalette

#' Rijkspalette function
#'
#' This function queries the Rijksmuseum collection for paintings and returns
#' a colour palette based on colours from that painting.
#'
#' @param query Keyword to search for in the collection of the Rijksmuseum
#'
#' @return an object of type \code{rijkspalette}
#'
#' @examples
#' pal <- rijksPalette("Vermeer Letter")
#' \donttest{
#' plot(pal)
#' barplot(1/sqrt(1:15), col = pal$palette(15))
#' }
#'
#' @seealso \code{\link{tune}}
#' @seealso \code{\link{explore}}
#'
#' @export
rijksPalette <- function(query) {
  call <- match.call()
  time <- Sys.time()
  downloadedImage <- rijksQuery(query)
  if (is.na(file.size(downloadedImage))) return()
  img <- imager::load.image(downloadedImage)
  labmat <- imgToLabmat(img)
  cols <- labmatToPalette(labmat, 5, 0.75)
  return(structure(list(call = call,
                        time = time,
                        imageLocation = downloadedImage,
                        img = img,
                        labmat = labmat,
                        cols = cols,
                        palette = grDevices::colorRampPalette(cols)),
                   class = "rijkspalette"))
}

Try the rijkspalette package in your browser

Any scripts or data that you put into this service are public.

rijkspalette documentation built on May 10, 2021, 5:07 p.m.