shrink_images: Shrink images to a maximum width

View source: R/image.R

shrink_imagesR Documentation

Shrink images to a maximum width

Description

Use magick::image_resize() to shrink an image if its width is larger than the value specified by the argument width, and optionally call tinify() to compress it.

Usage

shrink_images(
  width = 800,
  dir = ".",
  files = all_files("[.](png|jpe?g|webp)$", dir),
  tinify = FALSE
)

Arguments

width

The desired maximum width of images.

dir

The directory of images.

files

A vector of image file paths. By default, this is all ‘.png’, ‘.jpeg’, and ‘.webp’ images under dir.

tinify

Whether to compress images using tinify().

Examples

f = xfun:::all_files("[.](png|jpe?g)$", R.home("doc"))
file.copy(f, tempdir())
f = file.path(tempdir(), basename(f))
magick::image_info(magick::image_read(f))  # some widths are larger than 300
xfun::shrink_images(300, files = f)
magick::image_info(magick::image_read(f))  # all widths <= 300 now
file.remove(f)

yihui/xfun documentation built on April 29, 2024, 12:16 p.m.