| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/image.R |
| 3 |
\name{tinify} |
| 4 |
\alias{tinify} |
| 5 |
\alias{tinify_dir} |
| 6 |
\title{Use the Tinify API to compress PNG and JPEG images} |
| 7 |
\usage{ |
| 8 |
tinify( |
| 9 |
input, |
| 10 |
output, |
| 11 |
quiet = FALSE, |
| 12 |
force = FALSE, |
| 13 |
key = env_option("xfun.tinify.key"), |
| 14 |
history = env_option("xfun.tinify.history") |
| 15 |
) |
| 16 |
|
| 17 |
tinify_dir(dir = ".", ...) |
| 18 |
} |
| 19 |
\arguments{ |
| 20 |
\item{input}{A vector of input paths of images.} |
| 21 |
|
| 22 |
\item{output}{A vector of output paths or a function that takes \code{input} and |
| 23 |
returns a vector of output paths (e.g., \verb{output = }\code{\link{identity}} means |
| 24 |
\code{output = input}). By default, if the \code{history} argument is not a provided, |
| 25 |
\code{output} is \code{input} with a suffix \code{-min} (e.g., when \code{input = 'foo.png'}, |
| 26 |
\code{output = 'foo-min.png'}), otherwise \code{output} is the same as \code{input}, which |
| 27 |
means the original image files will be overwritten.} |
| 28 |
|
| 29 |
\item{quiet}{Whether to suppress detailed information about the compression, |
| 30 |
which is of the form \samp{input.png (10 Kb) ==> output.png (5 Kb, 50\%); |
| 31 |
compression count: 42}. The percentage after \code{output.png} stands for |
| 32 |
the compression ratio, and the compression count shows the number of |
| 33 |
compressions used for the current month.} |
| 34 |
|
| 35 |
\item{force}{Whether to compress an image again when it appears to have been |
| 36 |
compressed before. This argument only makes sense when the \code{history} |
| 37 |
argument is provided.} |
| 38 |
|
| 39 |
\item{key}{The Tinify API key. It can be set via either the global option |
| 40 |
\code{xfun.tinify.key} or the environment variable \code{R_XFUN_TINIFY_KEY} (see |
| 41 |
\code{\link[=env_option]{env_option()}}).} |
| 42 |
|
| 43 |
\item{history}{Path to a history file to record the MD5 checksum of |
| 44 |
compressed images. If the checksum of an expected output image exists in |
| 45 |
this file and \code{force = FALSE}, the compression will be skipped. This can |
| 46 |
help you avoid unnecessary API calls.} |
| 47 |
|
| 48 |
\item{dir}{A directory under which all \file{.png}, \file{.jpeg}, and |
| 49 |
\file{.webp} files are to be compressed.} |
| 50 |
|
| 51 |
\item{...}{Arguments passed to \code{\link[=tinify]{tinify()}}.} |
| 52 |
} |
| 53 |
\value{ |
| 54 |
The output file paths. |
| 55 |
} |
| 56 |
\description{ |
| 57 |
Compress PNG/JPEG images with \samp{api.tinify.com}, and download the |
| 58 |
compressed images. These functions require R packages \pkg{curl} and |
| 59 |
\pkg{jsonlite}. \code{tinify_dir()} is a wrapper function of \code{tinify()} to |
| 60 |
compress images under a directory. |
| 61 |
} |
| 62 |
\details{ |
| 63 |
You are recommended to set the API key in \file{.Rprofile} or |
| 64 |
\file{.Renviron}. After that, the only required argument of this function is |
| 65 |
\code{input}. If the original images can be overwritten by the compressed images, |
| 66 |
you may either use \code{output = identity}, or set the value of the \code{history} |
| 67 |
argument in \file{.Rprofile} or \file{.Renviron}. |
| 68 |
} |
| 69 |
\examples{ |
| 70 |
\dontrun{ |
| 71 |
f = xfun:::R_logo("jpg$") |
| 72 |
xfun::tinify(f) # remember to set the API key before trying this |
| 73 |
} |
| 74 |
} |
| 75 |
\references{ |
| 76 |
Tinify API: \url{https://tinypng.com/developers}. |
| 77 |
} |
| 78 |
\seealso{ |
| 79 |
The \pkg{tinieR} package (\url{https://github.com/jmablog/tinieR/}) is a |
| 80 |
more comprehensive implementation of the Tinify API, whereas |
| 81 |
\code{xfun::tinify()} has only implemented the feature of shrinking images. |
| 82 |
} |