tinify | R Documentation |
Compress PNG/JPEG images with ‘api.tinify.com’, and download the
compressed images. These functions require R packages curl and
jsonlite. tinify_dir()
is a wrapper function of tinify()
to
compress images under a directory.
tinify(
input,
output,
quiet = FALSE,
force = FALSE,
key = env_option("xfun.tinify.key"),
history = env_option("xfun.tinify.history")
)
tinify_dir(dir = ".", ...)
input |
A vector of input paths of images. |
output |
A vector of output paths or a function that takes |
quiet |
Whether to suppress detailed information about the compression,
which is of the form ‘input.png (10 Kb) ==> output.png (5 Kb, 50%);
compression count: 42’. The percentage after |
force |
Whether to compress an image again when it appears to have been
compressed before. This argument only makes sense when the |
key |
The Tinify API key. It can be set via either the global option
|
history |
Path to a history file to record the MD5 checksum of
compressed images. If the checksum of an expected output image exists in
this file and |
dir |
A directory under which all ‘.png’, ‘.jpeg’, and ‘.webp’ files are to be compressed. |
... |
Arguments passed to |
You are recommended to set the API key in ‘.Rprofile’ or
‘.Renviron’. After that, the only required argument of this function is
input
. If the original images can be overwritten by the compressed images,
you may either use output = identity
, or set the value of the history
argument in ‘.Rprofile’ or ‘.Renviron’.
The output file paths.
Tinify API: https://tinypng.com/developers.
The tinieR package (https://github.com/jmablog/tinieR/) is a
more comprehensive implementation of the Tinify API, whereas
xfun::tinify()
has only implemented the feature of shrinking images.
f = xfun:::R_logo("jpg$")
xfun::tinify(f) # remember to set the API key before trying this
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.