Polish list, loops, & map() intro.
This commit is contained in:
28
images/embed_jpg.R
Normal file
28
images/embed_jpg.R
Normal file
@@ -0,0 +1,28 @@
|
||||
is_latex <- function() {
|
||||
identical(knitr::opts_knit$get('rmarkdown.pandoc.to'), "latex")
|
||||
}
|
||||
|
||||
embed_jpg <- function(path, dpi) {
|
||||
dim <- jpg_dim(path)
|
||||
|
||||
if (is_latex()) {
|
||||
width <- round(dim[2] / dpi, 2)
|
||||
|
||||
knitr::asis_output(paste0(
|
||||
"\\includegraphics[",
|
||||
"width=", width, "in",
|
||||
"]{", path, "}"
|
||||
))
|
||||
} else {
|
||||
knitr::asis_output(paste0(
|
||||
"<img src='", path, "'",
|
||||
" width='", round(dim[2] / (dpi / 96)), "'",
|
||||
" height='", round(dim[1] / (dpi / 96)), "'",
|
||||
" />"
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
jpg_dim <- function(path) {
|
||||
dim(jpeg::readJPEG(path, native = TRUE))
|
||||
}
|
||||
BIN
images/pepper-1.jpg
Normal file
BIN
images/pepper-1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 186 KiB |
BIN
images/pepper-2.jpg
Normal file
BIN
images/pepper-2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
BIN
images/pepper-3.jpg
Normal file
BIN
images/pepper-3.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
BIN
images/pepper.jpg
Normal file
BIN
images/pepper.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 176 KiB |
Reference in New Issue
Block a user