Skip to content

Instantly share code, notes, and snippets.

@hadley
Created April 21, 2014 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/11154098 to your computer and use it in GitHub Desktop.
Save hadley/11154098 to your computer and use it in GitHub Desktop.
png <- function(path, dpi = NULL) {
meta <- attr(png::readPNG(path, native = TRUE, info = TRUE), "info")
if (!is.null(dpi)) meta$dpi <- rep(dpi, 2)
meta$path <- path
structure(meta, class = "png")
}
knit_print.png <- function(x, options) {
str(options)
knitr::asis_output(paste0(
"<img src='", x$path, "'",
" width=", x$dim[1] / (x$dpi[1] / 96),
" height=", x$dim[2] / (x$dpi[2] / 96),
" />"
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment