Skip to content

Commit

Permalink
enforce a deterministic result foo-fs8.png from pngquant
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Nov 15, 2016
1 parent 52effd2 commit be51bb7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/hooks-extra.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ hook_png = function(
#' @rdname chunk_hook
hook_pngquant = function(before, options, envir) {
if (is.null(options[['pngquant']])) options$pngquant = '--skip-if-larger'
options[['pngquant']] = paste(options[['pngquant']], '--ext -fs8.png')
hook_png(before, options, envir, 'pngquant', function(x) {
# pngquant creates an output file with '-fs8.png' as the extension.
x_opt = sub("\\.png$", "-fs8.png", x)
file.rename(x_opt, x)
x2 = sub("\\.png$", "-fs8.png", x)
if (file.exists(x2)) file.rename(x2, x)
})
}

Expand Down

0 comments on commit be51bb7

Please sign in to comment.