Title: | Optimize and Compress Image Files with 'reSmush.it' |
---|---|
Description: | Compress local and online images using the 'reSmush.it' API service <https://resmush.it/>. |
Authors: | Diego Hernangómez [aut, cre, cph] |
Maintainer: | Diego Hernangómez <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-10-18 06:40:36 UTC |
Source: | CRAN |
Optimize all the local files of a directory (or list of directories) using the reSmush.it API.
resmush_dir( dir, ext = "\\.(png|jpe?g|bmp|gif|tif)$", suffix = "_resmush", overwrite = FALSE, progress = TRUE, report = TRUE, recursive = FALSE, ... )
resmush_dir( dir, ext = "\\.(png|jpe?g|bmp|gif|tif)$", suffix = "_resmush", overwrite = FALSE, progress = TRUE, report = TRUE, recursive = FALSE, ... )
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
|
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.
reSmush.it API docs.
See resmush_clean_dir()
to clean a directory of previous runs.
Other functions for optimizing:
resmush_file()
,
resmush_url()
# 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)
# 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)
Optimize local images using the reSmush.it API.
resmush_file( file, suffix = "_resmush", overwrite = FALSE, progress = TRUE, report = TRUE, qlty = 92, exif_preserve = FALSE )
resmush_file( file, suffix = "_resmush", overwrite = FALSE, progress = TRUE, report = TRUE, qlty = 92, exif_preserve = FALSE )
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. |
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.
reSmush.it API docs.
See resmush_clean_dir()
to clean a directory of previous runs.
Other functions for optimizing:
resmush_dir()
,
resmush_url()
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)
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)
Optimize and download an online image using the reSmush.it API.
resmush_url( url, outfile = file.path(tempdir(), basename(url)), overwrite = FALSE, progress = TRUE, report = TRUE, qlty = 92, exif_preserve = FALSE )
resmush_url( url, outfile = file.path(tempdir(), basename(url)), overwrite = FALSE, progress = TRUE, report = TRUE, qlty = 92, exif_preserve = FALSE )
url |
url or a vector of urls pointing to hosted image files. reSmush can optimize the following image files:
|
outfile |
Path or paths where the optimized files would be store in
your disk. By default, temporary files (see |
overwrite |
Logical. Should |
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. |
Writes on disk the optimized file if the API call is successful. In all cases, a (invisible) data frame with a summary of the process is returned as well.
If any value of the vector outfile
is duplicated, resmush_url()
would
rename the output with a suffix _01. _02
, etc.
reSmush.it API docs.
Other functions for optimizing:
resmush_dir()
,
resmush_file()
# Base url base_url <- "https://raw.githubusercontent.com/dieghernan/resmush/main/inst/" png_url <- paste0(base_url, "/extimg/example.png") resmush_url(png_url) # Several urls jpg_url <- paste0(base_url, "/extimg/example.jpg") summary <- resmush_url(c(png_url, jpg_url)) # Returns an (invisible) data frame with a summary of the process summary # Display with png if (require("png", quietly = TRUE)) { my_png <- png::readPNG(summary$dest_img[1]) grid::grid.raster(my_png) } # Use with jpg and parameters resmush_url(jpg_url) resmush_url(jpg_url, qlty = 10)
# Base url base_url <- "https://raw.githubusercontent.com/dieghernan/resmush/main/inst/" png_url <- paste0(base_url, "/extimg/example.png") resmush_url(png_url) # Several urls jpg_url <- paste0(base_url, "/extimg/example.jpg") summary <- resmush_url(c(png_url, jpg_url)) # Returns an (invisible) data frame with a summary of the process summary # Display with png if (require("png", quietly = TRUE)) { my_png <- png::readPNG(summary$dest_img[1]) grid::grid.raster(my_png) } # Use with jpg and parameters resmush_url(jpg_url) resmush_url(jpg_url, qlty = 10)