| Title: | Optimize and Compress Images |
| Version: | 0.2 |
| Description: | Optimize and compress images using 'Rust' libraries to reduce file sizes while maintaining image quality. Currently supports lossless PNG optimization via the 'oxipng' crate. The package provides functions to optimize individual image files or entire directories, with configurable compression levels to balance between file size reduction and processing speed. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/yihui/tinyimg |
| BugReports: | https://github.com/yihui/tinyimg/issues |
| SystemRequirements: | Cargo (Rust's package manager), rustc |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Suggests: | testit |
| Config/rextendr/version: | 0.3.1 |
| NeedsCompilation: | yes |
| Packaged: | 2026-02-18 05:57:22 UTC; yihui |
| Author: | Yihui Xie |
| Maintainer: | Yihui Xie <xie@yihui.name> |
| Repository: | CRAN |
| Date/Publication: | 2026-02-20 10:30:02 UTC |
tinyimg: Optimize and Compress Images
Description
The tinyimg package provides tools for optimizing and compressing images using Rust libraries.
Author(s)
Maintainer: Yihui Xie xie@yihui.name (ORCID) (https://yihui.org) [copyright holder]
Other contributors:
Authors of the dependency Rust crates (see AUTHORS file) [contributor, copyright holder]
See Also
Useful links:
Optimize PNG images
Description
Optimize PNG files or directories of PNG files using lossless compression.
Usage
optim_png(
input,
output = identity,
level = 2L,
alpha = FALSE,
preserve = TRUE,
recursive = TRUE,
verbose = TRUE
)
Arguments
input |
Path to the input PNG file or directory. If a directory is provided,
all PNG files in the directory (and subdirectories if |
output |
Path to the output PNG file or directory, or a function that
takes an input file path and returns an output path. When optimizing a
directory, |
level |
Optimization level (0-6). Higher values result in better compression but take longer. |
alpha |
Optimize transparent pixels for better compression. This is technically lossy but visually lossless. |
preserve |
Preserve file permissions and timestamps. |
recursive |
When |
verbose |
Print file size reduction info for each file. |
Value
Character vector of output file paths (invisibly).
Examples
# Create a test PNG
tmp = tempfile()
png(tmp, width = 400, height = 400)
plot(1:10)
dev.off()
# Optimize with different levels
optim_png(tmp, paste0(tmp, "-o1.png"), level = 1)
optim_png(tmp, paste0(tmp, "-o6.png"), level = 6)