resmush_file: Optimize local image files

View source: R/resmush_file.R

resmush_fileR Documentation

Optimize local image files

Description

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

Usage

resmush_file(
  file,
  suffix = "_resmush",
  overwrite = FALSE,
  progress = TRUE,
  report = TRUE,
  qlty = 92,
  exif_preserve = FALSE
)

Arguments

file

A character vector of paths to local image files. The API can optimize PNG, JPEG, GIF, BMP and TIFF files.

suffix

A character string inserted before each output file extension. The default is "_resmush". Therefore, example.png becomes example_resmush.png. Values "", NA and NULL are equivalent to overwrite = TRUE.

overwrite

Logical. Should the input files be overwritten? If TRUE, suffix is ignored.

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 report = TRUE, a summary is displayed in the console.

See Also

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

Examples




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)

# Optimize multiple files.
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))

# 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_file(tmp_jpg)
resmush_file(tmp_jpg, qlty = 10)



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