R/jpg2png.R

Defines functions jpg2png

Documented in jpg2png

#' Convert a JPG image to png format
#'
#' A common task for photos captured with iPhone
#'
#' @param path Character. Path to one or more images to convert.
#'
#' @return Writes a copy of the JPG file as a png in the same directory.
#' @export
#'
jpg2png <- function(path){

  new_path <- stringr::str_replace(path, stringr::regex(pattern = 'jpg|jpeg', ignore_case = T), replacement = 'png')

  convert <- function(path = path){
    magick::image_read(path = path) %>%
      magick::image_convert(format = "png")
  }

  converted <- purrr::map(path, convert)

  args <- list(path = new_path, image = converted)

  purrr::pwalk(args, magick::image_write)

}
evanmascitti/ecmfuns documentation built on April 5, 2025, 1:52 a.m.