resmush_file {resmush}R Documentation

Optimize a local file

Description

Optimize local images using the reSmush.it API.

Usage

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

Arguments

file

Path or paths to local files. reSmush can optimize the following image files:

  • png

  • jpg/jpeg

  • gif

  • bmp

  • tiff

  • webp

suffix

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.

overwrite

Logical. Should the file in file be overwritten? If TRUE suffix would be ignored.

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 jpg files. Integer between 0 and 100 indicating the optimization level. For optimal results use vales above 90.

exif_preserve

Logical. Should the Exif information (if any) deleted? Default is to remove (i.e. exif_preserve = FALSE).

Value

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.

See Also

reSmush.it API docs.

See resmush_clean_dir() to clean a directory of previous runs.

Other functions for optimizing: resmush_dir(), resmush_url()

Examples




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)



[Package resmush version 0.1.0 Index]