jhelvy / jhelvy/renderthis

Add `resize_images()` function

Open
#26 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
HTML
Stars
178
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Based on this tweet thread, it would be helpful to be able to batch resize all of the images used in making xaringan slides to reduce the final file size of the PDF from build_pdf() or any of the other build_* functions. This should probably be implemented at the .Rmd level and maybe parse through the .Rmd file to look for all image types that can be resized. Template I'm thinking for the function is:

resize_images <- function(input, max_size = 1, image_types = c("png", "jpeg", "jpg") {}

Where max_size is the max image file size in MB, and image_types is the vector containing all image types to search for (the user can add more if they want).

Christophe Dervieux gave some suggestions in the tweet for how to do the resizing:

Optipng can be used to optimize image size. There is a hook: https://bookdown.org/yihui/rmarkdown-cookbook/optipng.html
But also xfun::optipng() https://rdrr.io/cran/xfun/man/optipng.html
They can also be compressed if needed and the new tinyfy() can help: https://rdrr.io/cran/xfun/man/tinify.html

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the build_pdf() and other build_* entry points to understand where image handling occurs, then review the proposed resize_images(input, max_size, image_types) interface. Check the xfun::optipng() and xfun::tinify() references for possible resizing approaches. Done means images found in the .Rmd can be processed by the selected types and output builds use the reduced files.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.