File: shrink_images.Rd

package info (click to toggle)
r-cran-xfun 0.37%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 792 kB
  • sloc: ansic: 242; sh: 22; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/image.R
\name{shrink_images}
\alias{shrink_images}
\title{Shrink images to a maximum width}
\usage{
shrink_images(
  width = 800,
  dir = ".",
  files = all_files("[.](png|jpe?g|webp)$", dir),
  tinify = FALSE
)
}
\arguments{
\item{width}{The desired maximum width of images.}

\item{dir}{The directory of images.}

\item{files}{A vector of image file paths. By default, this is all
\file{.png}, \file{.jpeg}, and \file{.webp} images under \code{dir}.}

\item{tinify}{Whether to compress images using \code{\link{tinify}()}.}
}
\description{
Use \code{\link[magick:image_resize]{magick::image_resize}()} to shrink an
image if its width is larger than the value specified by the argument
\code{width}, and optionally call \code{\link{tinify}()} to compress it.
}
\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)
}