resmush_url {resmush}R Documentation

Optimize an online file

Description

Optimize and download an online image using the reSmush.it API.

Usage

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

Arguments

url

url or a vector of urls pointing to hosted image files. reSmush can optimize the following image files:

  • png

  • jpg/jpeg

  • gif

  • bmp

  • tiff

  • webp

outfile

Path or paths where the optimized files would be store in your disk. By default, temporary files (see tempfile()) with the same basename() than the file provided in url would be created. It should be of the same length than url parameter.

overwrite

Logical. Should outfile be overwritten (if already exists)? If FALSE and outfile exists it would create a copy with a numerical suffix (i.e. ⁠<outfile>.png⁠, ⁠<outfile>_01.png⁠, etc.).

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 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.

See Also

reSmush.it API docs.

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

Examples





# 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)



[Package resmush version 0.1.0 Index]