| Title: | Optimize and Compress Image Files with 'reSmush.it' |
|---|---|
| Description: | Optimize and compress local image files, directories and online images with the 'reSmush.it' API <https://resmush.it/>. Supports 'png', 'jpg/jpeg', 'gif', 'bmp' and 'tiff' files. |
| Authors: | Diego Hernangómez [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-8457-4658>) |
| Maintainer: | Diego Hernangómez <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-06-03 13:19:51 UTC |
| Source: | https://github.com/dieghernan/resmush |
Optimize supported image files in one or more directories with 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 |
A character vector of paths to local directories. |
ext |
A |
suffix |
Character. Defaults to |
overwrite |
Logical. Should the files in |
progress |
Logical. Should a progress bar be displayed? |
report |
Logical. Should a summary report be displayed in the console? |
recursive |
Logical. Should file search within |
... |
Arguments passed on to
|
Writes optimized files to disk when the API call is successful. Invisibly returns a data frame summarizing the process.
reSmush.it API documentation.
See resmush_clean_dir() to clean a directory of previous runs.
Other functions for optimizing:
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") # Non-recursive. resmush_dir(dest_folder) resmush_clean_dir(dest_folder) # Recursive. summary <- resmush_dir(dest_folder, recursive = TRUE) # Return the same information in the invisible data frame. 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)# 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") # Non-recursive. resmush_dir(dest_folder) resmush_clean_dir(dest_folder) # Recursive. summary <- resmush_dir(dest_folder, recursive = TRUE) # Return the same information in the invisible data frame. 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)
Optimize one or more local image files with 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 image files. The API can optimize
|
suffix |
Character. Defaults to |
overwrite |
Logical. Should the file in |
progress |
Logical. Should a progress bar be displayed? |
report |
Logical. Should a summary report be displayed in the console? |
qlty |
Integer between |
exif_preserve |
Logical. Should
Exif metadata be preserved? The
default is |
Writes optimized files to disk when the API call is successful. Invisibly
returns a data frame summarizing the process. With report = TRUE, a summary
report is also displayed in the console.
reSmush.it API documentation.
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") # Copy to a temporary file for this example. 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) # Display a summary in the console. summary <- resmush_file(c(tmp_png, tmp_jpg)) # The invisible data frame contains the same information. summary # Display the `png` output. if (require("png", quietly = TRUE)) { my_png <- png::readPNG(summary$dest_img[1]) grid::grid.raster(my_png) } # Use with `jpg` files and parameters. resmush_file(tmp_jpg) resmush_file(tmp_jpg, qlty = 10)png_file <- system.file("extimg/example.png", package = "resmush") # Copy to a temporary file for this example. 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) # Display a summary in the console. summary <- resmush_file(c(tmp_png, tmp_jpg)) # The invisible data frame contains the same information. summary # Display the `png` output. if (require("png", quietly = TRUE)) { my_png <- png::readPNG(summary$dest_img[1]) grid::grid.raster(my_png) } # Use with `jpg` files and parameters. resmush_file(tmp_jpg) resmush_file(tmp_jpg, qlty = 10)
Optimize and download one or more online image files with 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 vector of URLs pointing to hosted image files. The API can
optimize |
outfile |
Path or paths where optimized files are stored on disk. By
default, temporary files are created with |
overwrite |
Logical. Should |
progress |
Logical. Should a progress bar be displayed? |
report |
Logical. Should a summary report be displayed in the console? |
qlty |
Integer between |
exif_preserve |
Logical. Should
Exif metadata be preserved? The
default is |
Writes optimized files to disk when the API call is successful. Invisibly
returns a data frame summarizing the process. If any value in outfile is
duplicated, resmush_url() renames the outputs with suffixes such as _01
and _02.
reSmush.it API documentation.
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)) # The invisible data frame contains a summary of the process. summary # Display the `png` output. if (require("png", quietly = TRUE)) { my_png <- png::readPNG(summary$dest_img[1]) grid::grid.raster(my_png) } # Use with `jpg` files 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)) # The invisible data frame contains a summary of the process. summary # Display the `png` output. if (require("png", quietly = TRUE)) { my_png <- png::readPNG(summary$dest_img[1]) grid::grid.raster(my_png) } # Use with `jpg` files and parameters. resmush_url(jpg_url) resmush_url(jpg_url, qlty = 10)