Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routine feature request: shrink png images #14

Open
gadenbuie opened this issue Mar 28, 2023 · 5 comments
Open

Routine feature request: shrink png images #14

gadenbuie opened this issue Mar 28, 2023 · 5 comments

Comments

@gadenbuie
Copy link
Member

gadenbuie commented Mar 28, 2023

It'd be helpful to add an action that

  • Installs optipng
  • Runs optipng on a list of directories provided to the action
  • Commits any updates to those files back to the repo

The actual code might look something like this:

# Shrink images in man/figures
sudo apt-get install optipng
optipng man/figures/*.png
git commit man/figures/*.png -m "Shrink images in man/figures (Github Action)" || echo "No changes to man/figures/*.png"

but it'd be extra helpful to allow an array input of directories.

- name: Shrink pngs
  uses: rstudio/shiny-workflows/shrink-png@v1
  with:
    paths:
      - man/figures/*.png
      - vignettes/**.png
@gadenbuie gadenbuie transferred this issue from rstudio/shinycoreci Mar 28, 2023
@gadenbuie
Copy link
Member Author

gadenbuie commented Mar 28, 2023

Motivation and MVP: rstudio/bslib#521

@wch
Copy link
Collaborator

wch commented Mar 28, 2023

I like the idea of running optipng on files.

It would be nice if it could quickly detect and skip files that are already optimized. In my experience, if there are a large number of PNGs, it can take a nontrivial amount of time to run. That said, there's not likely to be a lot of PNGs in /man/figures and /vignettes.

@gadenbuie
Copy link
Member Author

Good point @wch. Maybe we could limit optipng to rc- branches?

@wch
Copy link
Collaborator

wch commented Mar 29, 2023

It might make sense to just do it, if in practice it doesn't add a huge amount of time. We could also use a program that's faster than OptiPNG.

I came across an interesting discussion of PNG optimizers here: https://news.ycombinator.com/item?id=31655651
* Compression benchmarks: http://www.olegkikin.com/png_optimizers/
* Speed and compression benchmarks: https://css-ig.net/benchmark/png-lossless

It sounds like ECT is very good in terms of speed and file size, but it doesn't seem easy to install. oxipng also looks good, and I think is more widely available.

@wch
Copy link
Collaborator

wch commented Mar 29, 2023

Apparently oxipng is a rewrite of optipng in Rust. I just tested it against optipng, and it looks like it's about 30% faster on my machine. I think oxipng may be the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants