add_image_shadow | R Documentation |
This function adds a shadow to the image, archiving the original image in a separate archive sub-directory.
add_image_shadow(path_image)
path_image |
The character string of the image path name. |
An internal shadow may be added when the function is called for the first time. Calling the function a second time then adds a border shadow.
The path name of image returned invisibly so that the function can be used in a piped workflow.
Artwork by @allison_horst.
The example batch runs the function on a graph from the palmerpenguins package and is an example of parallelization using the future and furrr packages.
Other image manipulation functions:
reduce_image_size()
# example taken from Art for teaching with palmerpenguins.
# https://allisonhorst.github.io/palmerpenguins/articles/art.html
suppressPackageStartupMessages({
suppressWarnings({
library(fs)
library(here)
library(future)
library(furrr)
})
})
# create temp directory
dir_create(path(tempdir(), "figures"))
# copy image to temp directory
if(dir_exists(here("man", "figures"))) {
file_copy(here("man", "figures", "penguins.png"),
path(tempdir(), "figures", "penguins.png"))
}
# add shadows to graph image
plan(multisession)
path(tempdir(), "figures") %>% {
suppressMessages({dir_ls(., glob = "*.png")})} %>%
# internal shadow created
future_walk(add_image_shadow,
.options = furrr_options(seed = TRUE),
.progress = TRUE) %>%
# outer border shadow created
future_walk(add_image_shadow,
.options = furrr_options(seed = TRUE),
.progress = TRUE)
# move figures from temporary directory
if(dir_exists(here("man", "figures"))) {
file_move(path(tempdir(), "figures", "penguins.png"),
here("man", "figures", "penguins_shadow.png"))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.