resmush_url: Optimize online image files

View source: R/resmush_url.R

resmush_urlR Documentation

Optimize online image files

Description

Optimize and download one or more online image files with the reSmush.it API. The API is free for personal use and accepts files smaller than 5 MB.

Usage

resmush_url(
  url,
  outfile = file.path(tempdir(), basename(url)),
  overwrite = FALSE,
  progress = TRUE,
  report = TRUE,
  qlty = 92,
  exif_preserve = FALSE
)

Arguments

url

A character vector of URLs pointing to hosted image files. The API can optimize PNG, JPEG, GIF, BMP and TIFF files.

outfile

A character vector of paths where optimized files are stored. By default, files are created in tempdir() with the same basename() as each file in url. outfile must have the same length as url.

overwrite

Logical. Should existing files in outfile be overwritten? If FALSE, existing paths are made unique with a numeric suffix, such as example_01.png.

progress

Logical. Should a progress bar be displayed?

report

Logical. Should a summary report be displayed in the console?

qlty

An integer between 0 and 100 indicating the JPEG quality level. For best results, use values above 90. This argument only affects JPEG files.

exif_preserve

Logical. Should EXIF metadata be preserved? The default is FALSE. This removes it.

Value

An invisibly returned data frame with one row per result and columns containing source and destination paths, formatted and raw file sizes, compression ratios and status notes. Returns NULL if no result is available. Successful API calls also write the optimized files to disk. If outfile contains duplicate paths, resmush_url() makes them unique with suffixes such as ⁠_01⁠ and ⁠_02⁠.

See Also

Other image optimization functions: resmush_dir(), resmush_file()

Examples




# Define the base URL.
base_url <- "https://raw.githubusercontent.com/dieghernan/resmush/main/inst/"

png_url <- paste0(base_url, "/extimg/example.png")
resmush_url(png_url)

# Optimize multiple URLs.
jpg_url <- paste0(base_url, "/extimg/example.jpg")

summary <- resmush_url(c(png_url, jpg_url))

# Inspect the returned optimization summary.
summary

# Display the PNG output.
if (require("png", quietly = TRUE)) {
  my_png <- png::readPNG(summary$dest_img[1])
  grid::grid.raster(my_png)
}

# Adjust the JPEG quality level.
resmush_url(jpg_url)
resmush_url(jpg_url, qlty = 10)



resmush documentation built on July 2, 2026, 5:07 p.m.