
Last chance! 50% off unlimited learning
Sale ends in
Optimize local images using the reSmush.it API.
resmush_file(
file,
suffix = "_resmush",
overwrite = FALSE,
progress = TRUE,
report = TRUE,
qlty = 92,
exif_preserve = FALSE
)
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.
Path or paths to local files. reSmush can optimize the following image files:
png
jpg/jpeg
gif
bmp
tiff
Character, defaults to "_resmush"
. By default, a new file
with the suffix is created in the same directory than file
. (i.e.,
optimized example.png
would be example_resmush.png
). Values ""
, NA
and NULL
would be the same than overwrite = TRUE
.
Logical. Should the file in file
be overwritten? If TRUE
suffix
would be ignored.
Logical. Display a progress bar when needed.
Logical. Display a summary report of the process in the console. See also Value.
Only affects jpg
files. Integer between 0 and 100 indicating
the optimization level. For optimal results use vales above 90.
Logical. Should the
Exif information (if any) deleted?
Default is to remove it (i.e. exif_preserve = FALSE
).
reSmush.it API docs.
See resmush_clean_dir()
to clean a directory of previous runs.
Other functions for optimizing:
resmush_dir()
,
resmush_url()
# \donttest{
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)
# }
Run the code above in your browser using DataLab