resmush_dir {resmush} | R Documentation |
Optimize files of several directories
Description
Optimize all the local files of a directory (or list of directories) using the reSmush.it API.
Usage
resmush_dir(
dir,
ext = "\\.(png|jpe?g|bmp|gif|tif)$",
suffix = "_resmush",
overwrite = FALSE,
progress = TRUE,
report = TRUE,
recursive = FALSE,
...
)
Arguments
dir |
Character or vector of characters representing paths of local directories. |
ext |
|
suffix |
Character, defaults to |
overwrite |
Logical. Should the files in |
progress |
Logical. Display a progress bar when needed. |
report |
Logical. Display a summary report of the process in the console. See also Value. |
recursive |
Logical. Should the |
... |
Arguments passed on to
|
Value
Writes on disk the optimized file if the API call is successful in the
directories specified in dir
.
In all cases, a (invisible) data frame with a summary of the process is returned as well.
See Also
reSmush.it API docs.
See resmush_clean_dir()
to clean a directory of previous runs.
Other functions for optimizing:
resmush_file()
,
resmush_url()
Examples
# Get example dir and copy
example_dir <- system.file("extimg", package = "resmush")
temp_dir <- tempdir()
file.copy(example_dir, temp_dir, recursive = TRUE)
# Dest folder
dest_folder <- file.path(tempdir(), "extimg")
# Non-recursive
resmush_dir(dest_folder)
resmush_clean_dir(dest_folder)
# Recursive
summary <- resmush_dir(dest_folder, recursive = TRUE)
# Same info in the invisible df
summary[, -c(1, 2)]
# Display with png
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 example
unlink(dest_folder, force = TRUE, recursive = TRUE)