add_image_shadow: Add a shadow to an image

View source: R/display.R

add_image_shadowR Documentation

Add a shadow to an image

Description

This function adds a shadow to the image, archiving the original image in a separate archive sub-directory.

Usage

add_image_shadow(path_image)

Arguments

path_image

The character string of the image path name.

Details

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.

Value

The path name of image returned invisibly so that the function can be used in a piped workflow.

Figures

penguins_shadow.png

Artwork by @allison_horst.

See Also

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()

Examples

# 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"))
}

gcfrench/store documentation built on May 17, 2024, 5:52 p.m.