From 40318343134c674e1267b656314d14cbdcc0edaa Mon Sep 17 00:00:00 2001 From: Matthew Kay Date: Wed, 21 Feb 2024 22:34:38 -0600 Subject: [PATCH] try to use pngquant to compress vignette images on cran --- .github/workflows/R-CMD-check.yaml | 5 +++++ vignettes/children/chunk_options.txt | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index c5e30040..6269372d 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -65,6 +65,11 @@ jobs: sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") sudo -s eval "$sysreqs" + - name: Install pngquant + if: runner.os == 'Linux' + run: | + sudo apt-get install -y pngquant + - name: Install dependencies run: | remotes::install_deps(dependencies = TRUE) diff --git a/vignettes/children/chunk_options.txt b/vignettes/children/chunk_options.txt index 27924968..b3801f61 100755 --- a/vignettes/children/chunk_options.txt +++ b/vignettes/children/chunk_options.txt @@ -8,7 +8,10 @@ img { ```{r chunk_options, include=FALSE} -if (requireNamespace("pkgdown", quietly = TRUE) && pkgdown::in_pkgdown()) { +in_pkgdown = requireNamespace("pkgdown", quietly = TRUE) && pkgdown::in_pkgdown() + +# image dimensions +if (in_pkgdown) { tiny_width = 5.5 tiny_height = 3 + 2/3 small_width = med_width = 6.75 @@ -25,12 +28,13 @@ if (requireNamespace("pkgdown", quietly = TRUE) && pkgdown::in_pkgdown()) { large_width = 5.5 large_height = 2/3 } - knitr::opts_chunk$set( fig.width = small_width, fig.height = small_height ) -if (requireNamespace("ragg", quietly = TRUE)) { + +# graphics device +if (requireNamespace("ragg", quietly = TRUE) && in_pkgdown) { knitr::opts_chunk$set( dev = "ragg_png" ) @@ -40,4 +44,10 @@ if (requireNamespace("ragg", quietly = TRUE)) { dev.args = list(type = "cairo") ) } + +# png compression for CRAN +if (!in_pkgdown) { + knitr::knit_hooks$set(pngquant = knitr::hook_pngquant) + knitr::opts_chunk$set(pngquant = "--speed=1 --quality=50") +} ```