Movatterモバイル変換


[0]ホーム

URL:


resmushresmush website

CRAN statusCRAN resultsDownloadsR-CMD-checkR-hubcodecovCodeFactorr-universeDOIProject Status: Active – The project has reached a stable, usable state and is being actively developed.status

resmush is aR package that allowusers to optimize and compress images usingreSmush.it. reSmush.itis afree API that provides image optimization, and it has beenimplemented onWordPress,Drupal andmany more.

Some of the features ofreSmush.it are:

Installation

Installresmush fromCRANwith:

install.packages("resmush")

You can install the development version ofresmushfromGitHub with:

remotes::install_github("dieghernan/resmush")

Alternatively, you can installresmush using ther-universe:

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

Example

Compressing an onlinejpg image:

library(resmush)url<-paste0("https://raw.githubusercontent.com/dieghernan/","resmush/main/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

Optimized file

Original picture (top) 178.7 Kb and optimized picture (bottom) 45 Kb(Compression 74.8%). Click to enlarge.

The quality of the compression can be adjusted in the case ofjpg files using the parameterqlty. However,it is recommended to keep this value above 90 to get a good imagequality.

# Extreme caseresmush_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

Low quality image due to a high compression rate.

All the functions return invisibly a data set with a summary of theprocess. The next example shows how when compressing a local file.

png_file<-system.file("extimg/example.png",package ="resmush")# For the example, copy to a temporary filetmp_png<-tempfile(fileext =".png")file.copy(png_file, tmp_png,overwrite =TRUE)#> [1] TRUEsummary<-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

There are other alternatives for optimizing images withR:

toolCRANAdditional software?Online?API Key?Limits?
xfun::tinify()YesNoYesYes500 files/month (Free tier)
xfun::optipng()YesYesNoNoNo
tinieRNoNoYesYes500 files/month (Free tier)
optoutNoYesNoNoNo
resmushYesNoYesNoMax size 5Mb

Table 1: R packages: Comparison of alternatives foroptimizing images.

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

Table 2: R packages: Formats admitted.

Citation

Hernangómez D (2024).resmush: Optimize and Compress Image Fileswith 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 = {2024},  version = {0.2.1},  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: SupportingFunctions for Packages Maintained by Yihui Xie.https://github.com/yihui/xfun.

[8]ページ先頭

©2009-2025 Movatter.jp