R/image.R

Defines functions make_svg_responsive

Documented in make_svg_responsive

#' Make svg responsive
#'
#' @param svgfile a filepath
#'
#' @return none.
#' @export
make_svg_responsive <- function(svgfile){
  readLines(svgfile, n=1) -> svgline1
  if(stringr::str_detect(svgline1, "(width|height)")){
    svglines <- readLines(svgfile)
    svglines[[1]] |>
      # "width=\"111\" height=\"102\" viewBox=\"0 0 111 102\" fill=\"none\" " |>
      stringr::str_remove_all(
        "(width|height)[\\s=0-9\\\"]+"
      ) -> svglines[[1]]
    svglines |> writeLines(svgfile)
  }
  message('done.')
}
tpemartin/econWeb documentation built on Oct. 6, 2022, 1:14 a.m.