-
-
Notifications
You must be signed in to change notification settings - Fork 334
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
how to downscale, compress non-knitr images #51
Comments
Thanks for sharing! I guess this, along with other related issues you posted to knitr and bookdown, will remain fairly low priority for at least a few months. Anyway, if I were to crack this problem, I'd just use a shell script that calls |
thanks for the pointer @yihui – I moved over to Not sure how I missed that fantastic package in the first place. |
This is pretty cool. I personally use a imageoptim git hook that compresses all *.png and *.jpg how I want upon checking into source control. |
I prefer not to solve this specific issue, but provide a completely general solution instead: blogdown will execute the script |
This isn't really a feature request, just wanted to document a way I was going about the problem.
Maybe @yihui will find this worthwhile to pursue as a
blogdown
feature, I'll be happy to try and develop this into a PR then, though I'm not sure where in the stack this "belongs", and/or whether it's a wise idea to do this in R at all.In more general use-cases of
blogdown()
, involving a lot of non-knitr assets (knitr can deal with resolution and compression itself), people (like myself) might want to programmatically reduce the filesize of assets instatic/img
.Hugo itself doesn't (yet?) offer this kind of thing, and there is specialised software out there that a lot of people seem to recommend, such as hugulp.
I was looking for a simple solution that would work just with R and on travis (for deployment), without any additional dependencies and stuff I don't know how to use.
So I hacked together a little script to do this exclusively in R, to be found here.
If you add this to some
compression.R
at your project root:and then, for Travis fun, amend your
_build.sh
like so:Travis will then compress and rescale all
*.jpg
files bigger thancutoff
as specified.For now, only the x dim can be specified, and the y will be scaled accordingly, to retain the aspect ratio.
Ps.: one important addition would be to avoid re-scaling/compressing knitr assets. That would be stupid.
The text was updated successfully, but these errors were encountered: