compress_images: Minify size your images

Description Usage Arguments Value Examples

View source: R/compress_images.R

Description

Minify size of images located in a directory and output results in another directory.

You will be able to use this function only if

Usage

1
2
3
4
5
6
7
8
9
compress_images(
  input,
  output = NULL,
  verbose = TRUE,
  overwrite = FALSE,
  jpg_quality = "75",
  png_quality = "20-50",
  gif_colors = "64"
)

Arguments

input, output

input and output directories

verbose

should a log be printed in the console, default to TRUE.

overwrite

logical; should existing destination files be overwritten?

jpg_quality

Scale quantization tables to adjust image quality. Quality is "0" (worst) to "100" (best); default is "75".

png_quality

defined as "min-max", instructs pngquant to use the least amount of colors required to meet or exceed the max quality. If conversion results in quality below the min quality the image won't be saved.

gif_colors

Reduce the number of distinct colors in each output GIF to gif_colors or less. It must be between 2 and 256. This can be used to shrink output GIFs or eliminate any local color tables.

Value

a data.frame with details about input files and compressed files.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(minimage)
library(locatexec)

was_avail <- compress_images_available()

if(exec_available("node") && exec_available("npm")){

  if(!was_avail)
    compress_images_install(force = TRUE)

  # generate dest folder
  new_dir <- tempfile()
  dir.create(new_dir)

  # run compression
  z <- compress_images(system.file(package = "minimage", "test-files"), new_dir)

  print(z)

  if(!was_avail)
    compress_images_uninstall()

}

ardata-fr/minimage documentation built on Aug. 24, 2021, 2:21 a.m.