From be51bb793f95a7d2d36f4732039d89511853b013 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 15 Nov 2016 14:45:38 -0600 Subject: [PATCH] enforce a deterministic result foo-fs8.png from pngquant --- R/hooks-extra.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/hooks-extra.R b/R/hooks-extra.R index a22ac2c299..e46fdf70ea 100644 --- a/R/hooks-extra.R +++ b/R/hooks-extra.R @@ -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) }) }