| resmush_dir | R Documentation |
Optimize supported image files in one or more directories with the reSmush.it API. The API is free for personal use and accepts files smaller than 5 MB.
resmush_dir(
dir,
ext = "\\.(png|jpe?g|bmp|gif|tif)$",
suffix = "_resmush",
overwrite = FALSE,
progress = TRUE,
report = TRUE,
recursive = FALSE,
...
)
dir |
A character vector of paths to local directories. |
ext |
A |
suffix |
A character string inserted before each output file extension.
The default is |
overwrite |
Logical. Should the input files be overwritten? If |
progress |
Logical. Should a progress bar be displayed? |
report |
Logical. Should a summary report be displayed in the console? |
recursive |
Logical. Should the file search within |
... |
Arguments passed on to
|
An invisibly returned data frame with one row per result and columns
containing source and destination paths, formatted and raw file sizes,
compression ratios and status notes. Returns NULL if no result is
available. Successful API calls also write the optimized files to disk.
resmush_clean_dir() removes output files created by previous runs.
The reSmush.it API documentation describes the external service.
Other image optimization functions:
resmush_file(),
resmush_url()
# Copy the example directory.
example_dir <- system.file("extimg", package = "resmush")
temp_dir <- tempdir()
file.copy(example_dir, temp_dir, recursive = TRUE)
# Create the destination folder path.
dest_folder <- file.path(tempdir(), "extimg")
# Optimize files non-recursively.
resmush_dir(dest_folder)
resmush_clean_dir(dest_folder)
# Optimize files recursively.
summary <- resmush_dir(dest_folder, recursive = TRUE)
# Inspect the returned optimization summary.
summary[, -c(1, 2)]
# Display the PNG output.
if (require("png", quietly = TRUE)) {
a_png <- grepl("png$", summary$dest_img)
my_png <- png::readPNG(summary[a_png, ]$dest_img[2])
grid::grid.raster(my_png)
}
# Clean up the example files.
unlink(dest_folder, force = TRUE, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.