R/plot.R

#' Read PNG or JPG
#'
#' @param x object
#' @param ... other
#'
#' @export
load_image <- function(x, ...) {
  # Get extention
  ext <- tolower(tools::file_ext(basename(x)))
  if (ext %in% c("jpeg", "jpg")) {
    img <- jpeg::readJPEG(x)
  } else if (ext == "png") {
    img <- png::readPNG(x)
  }
  return(img)
}

#' Plot captcha
#'
#' @param x object
#' @param y -
#' @param ... other
#'
#' @export
plot.captcha <- function(x, y, ...) {
  img <- load_image(x)
  op <- graphics::par(mar = rep(0, 4))
  graphics::plot(grDevices::as.raster(img))
  graphics::par(op)
}
marceloturim/decryptr documentation built on May 14, 2019, 5:26 p.m.