GithubHelp home page GithubHelp logo

dieghernan / resmush Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 32.74 MB

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

Home Page: https://dieghernan.github.io/resmush/

License: Other

R 99.17% TeX 0.83%
compress-images optimize-images r r-package resmushit api

resmush's Introduction

resmush resmush website

CRAN status CRAN results Downloads R-CMD-check R-hub codecov r-universe CodeFactor DOI Project Status: Active – The project has reached a stable, usable state and is being actively developed. status

resmush is a R package that allow users to optimize and compress images using reSmush.it. reSmush.it is a free API that provides image optimization, and it has been implemented on WordPress, Drupal and many more.

Some of the features of reSmush.it are:

  • Free optimization services, no API key required.
  • Optimize local and online images.
  • Image files supported: png, jpg/jpeg, gif, bmp, tiff, webp.
  • Max image size: 5 Mb.
  • Compression via several algorithms:
    • PNGQuant: Strip unneeded chunks from pngs, preserving a full alpha transparency.
    • JPEGOptim: Lossless optimization based on optimizing the Huffman tables.
    • OptiPNG: png reducer that is used by several online optimizers.

Installation

Install resmush from CRAN with:

install.packages("resmush")

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

remotes::install_github("dieghernan/resmush")

Alternatively, you can 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 <- 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 of jpg files using the parameter qlty. However, it is recommended to keep this value above 90 to get a 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

Low quality image due to a high compression rate.

All the functions return invisibly a data set with a summary of the process. 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 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

There are other alternatives for optimizing images with R:

  • xfun (Xie 2024), which includes the following functions for optimizing image files:
    • xfun::tinify() is similar to resmush_file() but uses TinyPNG. An API key is required.
    • xfun::optipng() compresses local files with OptiPNG (which needs to be installed locally).
  • tinieR package by jmablog. An R package that provides a full interface with TinyPNG.
  • optout package by @coolbutuseless. Similar to xfun::optipng() with more options. Requires additional software to be installed locally.
tool CRAN Additional software? Online? API Key? Limits?
xfun::tinify() Yes No Yes Yes 500 files/month (Free tier)
xfun::optipng() Yes Yes No No No
tinieR No No Yes Yes 500 files/month (Free tier)
optout No Yes No No No
resmush Yes No Yes No Max size 5Mb

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

tool png jpg gif bmp tiff webp pdf
xfun::tinify()
xfun::optipng()
tinieR
optout
resmush

Table 2: R packages: Formats admitted.

Citation

Hernangómez D (2024). resmush: Optimize and Compress Image Files with reSmush.it. doi:10.5281/zenodo.10556679, 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}},
  author = {Diego Hernangómez},
  year = {2024},
  version = {0.1.1},
  doi = {10.5281/zenodo.10556679},
  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.

resmush's People

Contributors

dieghernan avatar github-actions[bot] avatar imgbotapp avatar

Stargazers

 avatar

Watchers

 avatar  avatar

resmush's Issues

pkgcheck results - main

Checks for resmush (v0.0.0.9000)

git hash: 6cd19282

  • ✔️ Package name is available
  • ✔️ has a 'codemeta.json' file.
  • ✖️ does not have a 'contributing' file.
  • ✔️ uses 'roxygen2'.
  • ✔️ 'DESCRIPTION' has a URL field.
  • ✔️ 'DESCRIPTION' has a BugReports field.
  • ✔️ Package has at least one HTML vignette
  • ✔️ All functions have examples.
  • ✔️ Package has continuous integration checks.
  • ✔️ Package coverage is 100%.
  • ✔️ R CMD check found no errors.
  • ✔️ R CMD check found no warnings.

Important: All failing checks above must be addressed prior to proceeding

Package License: MIT + file LICENSE


1. Package Dependencies

Details of Package Dependency Usage (click to open)

The table below tallies all function calls to all packages ('ncalls'), both internal (r-base + recommended, along with the package itself), and external (imported and suggested packages). 'NA' values indicate packages to which no identified calls to R functions could be found. Note that these results are generated by an automated code-tagging system which may not be entirely accurate.

type package ncalls
internal base 82
internal resmush 12
internal stats 2
imports httr 9
imports cli 5
imports utils 1
imports curl NA
suggests knitr NA
suggests rmarkdown NA
suggests testthat NA
linking_to NA NA

Click below for tallies of functions used in each package. Locations of each call within this package may be generated locally by running 's <- pkgstats::pkgstats(<path/to/repo>)', and examining the 'external_calls' table.

base

file (10), c (5), length (5), url (5), as.integer (4), format (4), getOption (4), lapply (4), units (4), vapply (4), file.size (3), for (3), seq_len (3), basename (2), body (2), character (2), data.frame (2), do.call (2), list (2), paste0 (2), seq (2), strsplit (2), unlist (2), dirname (1), file.path (1), system.file (1), tempdir (1)

resmush

my_file_ext (2), name_sans_ext (2), resmush_file_single (2), load_inst_to_temp (1), make_object_size (1), make_unique_paths (1), resmush_file (1), resmush_url_single (1), smush_from_url (1)

httr

GET (3), content (2), write_disk (2), POST (1), upload_file (1)

cli

cli_bullets (5)

stats

df (2)

utils

object.size (1)

NOTE: Some imported packages appear to have no associated function calls; please ensure with author that these 'Imports' are listed appropriately.


2. Statistical Properties

This package features some noteworthy statistical properties which may need to be clarified by a handling editor prior to progressing.

Details of statistical properties (click to open)

The package has:

  • code in R (100% in 4 files) and
  • 1 authors
  • 1 vignette
  • no internal data file
  • 4 imported packages
  • 2 exported functions (median 18 lines of code)
  • 18 non-exported functions in R (median 16 lines of code)

Statistical properties of package structure as distributional percentiles in relation to all current CRAN packages
The following terminology is used:

  • loc = "Lines of Code"
  • fn = "function"
  • exp/not_exp = exported / not exported

All parameters are explained as tooltips in the locally-rendered HTML version of this report generated by the checks_to_markdown() function

The final measure (fn_call_network_size) is the total number of calls between functions (in R), or more abstract relationships between code objects in other languages. Values are flagged as "noteworthy" when they lie in the upper or lower 5th percentile.

measure value percentile noteworthy
files_R 4 28.3
files_vignettes 1 68.4
files_tests 4 79.0
loc_R 249 27.8
loc_vignettes 83 19.8
loc_tests 453 73.0
num_vignettes 1 64.8
n_fns_r 20 27.9
n_fns_r_exported 2 6.8
n_fns_r_not_exported 18 37.6
n_fns_per_file_r 3 54.5
num_params_per_fn 5 69.6
loc_per_fn_r 18 54.7
loc_per_fn_r_exp 18 42.5
loc_per_fn_r_not_exp 16 52.7
rel_whitespace_R 32 46.2
rel_whitespace_vignettes 39 24.1
rel_whitespace_tests 40 83.4
doclines_per_fn_exp 65 76.5
doclines_per_fn_not_exp 0 0.0 TRUE
fn_call_network_size 11 34.5

2a. Network visualisation

An interactive visualisation of calls between objects in the package has been uploaded as a workflow artefact. To view it, click on results from the latest 'pkgcheck' action, scroll to the bottom, and click on the 'visual-network' artefact.


3. goodpractice and other checks

Details of goodpractice checks (click to open)

3a. Continuous Integration Badges

check-full.yaml

GitHub Workflow Results

id name conclusion sha run_number date
7610847482 Clear all Github actions caches manually success 6aa6fb 2 2024-01-22
7615356135 lintr success 6cd192 18 2024-01-22
7615375341 pages build and deployment with artifacts-next success c92e1c 16 2024-01-22
7616446965 pkgcheck NA 6cd192 1 2024-01-22
7615356137 pkgdown-gh-pages success 6cd192 14 2024-01-22
7615356136 R-CMD-check success 6cd192 19 2024-01-22
7615356138 test-coverage success 6cd192 18 2024-01-22

3b. goodpractice results

R CMD check with rcmdcheck

R CMD check generated the following note:

  1. checking package subdirectories ... NOTE
    Problems with news in ‘NEWS.md’:
    No news entries found.

Test coverage with covr

Package coverage: 100

Cyclocomplexity with cyclocomp

No functions have cyclocomplexity >= 15

Static code analyses with lintr

lintr found no issues with this package!


Package Versions

package version
pkgstats 0.1.3.9
pkgcheck 0.1.2.11

Release resmush 0.1.0

First release:

Prepare for release:

  • git pull
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Finish & publish blog post
  • Add link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • Tweet

Release resmush 0.1.1

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.