13.2 Optimize PNG plots
If you have installed the program OptiPNG (http://optipng.sourceforge.net), you may use the hook knitr::hook_optipng()
to optimize PNG plot files to a smaller size without losing the image quality.
knitr::knit_hooks$set(optipng = knitr::hook_optipng)
After you set up this hook, you can use the chunk option optipng
to pass command-line arguments to OptiPNG, e.g., optipng = '-o7'
. These command-line arguments are optional, which means you can just use optipng = ''
to enable the hook for a code chunk. Please see the user manual on the website of OptiPNG to know the possible arguments.
Note that macOS users can easily install OptiPNG with Homebrew (https://brew.sh): brew install optipng
.
当前内容版权归 Chapman & Hall/CRC 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Chapman & Hall/CRC .