resmush_file {resmush} | R Documentation |
Optimize a local file
Description
Optimize local images using the reSmush.it API.
Usage
resmush_file(
file,
suffix = "_resmush",
overwrite = FALSE,
progress = TRUE,
report = TRUE,
qlty = 92,
exif_preserve = FALSE
)
Arguments
file |
Path or paths to local files. reSmush can optimize the following image files:
|
suffix |
Character, defaults to |
overwrite |
Logical. Should the file in |
progress |
Logical. Display a progress bar when needed. |
report |
Logical. Display a summary report of the process in the console. See also Value. |
qlty |
Only affects |
exif_preserve |
Logical. Should the
Exif information (if any) deleted?
Default is to remove it (i.e. |
Value
Writes on disk the optimized file if the API call is successful in the
same directory than file
.
With the option report = TRUE
a summary report is displayed in the
console. In all cases, a (invisible) data frame with a summary of the
process used for generate the report is returned.
See Also
reSmush.it API docs.
See resmush_clean_dir()
to clean a directory of previous runs.
Other functions for optimizing:
resmush_dir()
,
resmush_url()
Examples
png_file <- system.file("extimg/example.png", package = "resmush")
# For the example, copy to a temporary file
tmp_png <- tempfile(fileext = ".png")
file.copy(png_file, tmp_png, overwrite = TRUE)
resmush_file(tmp_png)
# Several paths
jpg_file <- system.file("extimg/example.jpg", package = "resmush")
tmp_jpg <- tempfile(fileext = ".jpg")
file.copy(jpg_file, tmp_jpg, overwrite = TRUE)
# Output summary in console
summary <- resmush_file(c(tmp_png, tmp_jpg))
# Similar info in an (invisible) data frame as a result
summary
# Display with png
if (require("png", quietly = TRUE)) {
my_png <- png::readPNG(summary$dest_img[1])
grid::grid.raster(my_png)
}
# With parameters
resmush_file(tmp_jpg)
resmush_file(tmp_jpg, qlty = 10)