MyNixOS website logo
Description

Optimize and Compress Image Files with 'reSmush.it'.

Compress local and online images using the 'reSmush.it' API service <https://resmush.it/>.

resmush resmush website

CRANstatus CRANresults Downloads R-CMD-check codecov CodeFactor r-universe DOI Project Status: Active - The project has reached a stable, usablestate and is being activelydeveloped. status

resmush is a R package that allows users to optimize and compress images using reSmush.it. reSmush.it is a free AP/u that provides image optimization and has been implemented in WordPress and many other tools.

Some of the features of reSmush.it include:

  • Free optimization services with no API key required.
  • Support for both local and online images.
  • Supported image formats: png, jpg/jpeg, gif, bmp, tiff.
  • Maximum image size: 5 MB.
  • Compression using several algorithms:
    • PNGQuant: Removes unnecessary chunks from png files while preserving a full alpha transparency.
    • JPEGOptim: Lossless optimization based on Huffman table optimization.
    • OptiPNG: A png optimizer used by several online compression tools.

Installation

Install resmush from CRAN with:

install.packages("resmush")

Check the docs of the developing version in https://dieghernan.github.io/resmush/dev/.

You can install the development version of resmush from GitHub with:

# install.packages("pak")
pak::pak("dieghernan/resmush")

Alternatively, install resmush using the r-universe:

# Install resmush in R:
install.packages(
  "resmush",
  repos = c(
    "https://dieghernan.r-universe.dev",
    "https://cloud.r-project.org"
  )
)

Example

Compressing an online jpg image:

library(resmush)

url <- "https://dieghernan.github.io/resmush/img/jpg_example_original.jpg"

resmush_url(
  url,
  outfile = "man/figures/jpg_example_compress.jpg",
  overwrite = TRUE
)
#> ══ resmush summary ═════════════════════════════════════════════════════════════
#> ℹ Input: 1 url with size 178.7 Kb
#> ✔ Success for 1 url: Size now is 45 Kb (was 178.7 Kb). Saved 133.7 Kb (74.82%).
#> See result in directory 'man/figures'.

Original uncompressed file(a)

Optimized file(b)

Figure 1: Original picture (a): 178.7 KB; Optimized picture (b): 45 KB (Compression: 74.8%). Click to enlarge.

The compression quality for jpg files can be adjusted using the qlty argument. However, it is recommended to keep this value above 90 to maintain good image quality.

# Extreme case
resmush_url(
  url,
  outfile = "man/figures/jpg_example_compress_low.jpg",
  overwrite = TRUE,
  qlty = 3
)
#> ══ resmush summary ═════════════════════════════════════════════════════════════
#> ℹ Input: 1 url with size 178.7 Kb
#> ✔ Success for 1 url: Size now is 2.2 Kb (was 178.7 Kb). Saved 176.4 Kb (98.74%).
#> See result in directory 'man/figures'.

Low quality figure

Figure 2: Low-quality image due to high compression (qlty = 3).

All the functions return (invisibly) a dataset summarizing the process. The following example shows how this works when compressing a local file:

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)
#> [1] TRUE

summary <- resmush_file(tmp_png, overwrite = TRUE)

tibble::as_tibble(summary[, -c(1, 2)])
#> # A tibble: 1 × 6
#>   src_size dest_size compress_ratio notes src_bytes dest_bytes
#>   <chr>    <chr>     <chr>          <chr>     <dbl>      <dbl>
#> 1 239.9 Kb 70.7 Kb   70.54%         OK       245618      72356

Other alternatives

Several other R packages also provide image optimization tools:

  • xfun (Xie 2024), which includes:
    • xfun::tinify(): Similar to resmush_file() but uses TinyPNG and requires an API key.
    • xfun::optipng(): Compresses local files using OptiPNG, which must be installed locally.
  • tinieR by jmablog: An R interface to TinyPNG.
  • optout by @coolbutuseless: Similar to xfun::optipng() but with more options. Requires additional local software.
toolCRANAdditional software?Online?API Key?Limits?
xfun::tinify()YesNoYesYes500 files/month (free tier)
xfun::optipng()YesYesNoNoNo
tinieRNoNoYesYes500 files/month (free tier)
optoutNoYesNoNoNo
resmushYesNoYesNoMax size 5 MB

Table 1: R packages: Comparison of alternatives for optimizing images.

toolpngjpggifbmptiffwebppdf
xfun::tinify()
xfun::optipng()
tinieR
optout
resmush

Table 2: R packages: Supported formats.

Citation

Hernangómez D (2026). resmush: Optimize and Compress Image Files with reSmush.it. doi:10.32614/CRAN.package.resmush, https://dieghernan.github.io/resmush/.

A BibTeX entry for LaTeX users is

@Manual{R-resmush,
  title = {{resmush}: Optimize and Compress Image Files with {reSmush.it}},
  doi = {10.32614/CRAN.package.resmush},
  author = {Diego Hernangómez},
  year = {2026},
  version = {1.0.0},
  url = {https://dieghernan.github.io/resmush/},
  abstract = {Compress local and online images using the reSmush.it API service <https://resmush.it/>.},
}

References

Xie, Yihui. 2024. xfun: Supporting Functions for Packages Maintained by Yihui Xie. https://github.com/yihui/xfun.

Metadata

Version

1.0.0

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows