From e2c72993dfd5dbb3eeb297da46b6ff7c9cb478f9 Mon Sep 17 00:00:00 2001 From: Asger Hautop Drewsen Date: Tue, 13 Apr 2021 10:00:47 +0200 Subject: [PATCH 1/2] Add option to save PNG without transparency --- app.js | 7 +++++-- static/index.html | 8 ++++++++ static/latex2image-client.js | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index f20e30a..67a8904 100644 --- a/app.js +++ b/app.js @@ -97,8 +97,11 @@ conversionRouter.post('/convert', async (req, res) => { // Convert to PNG } else if (fileFormat === 'png') { - await sharp(inputSvgFileName, { density: 96 }) - .toFile(outputFileName); // Sharp's PNG type is implicitly determined via the output file extension + let s = sharp(inputSvgFileName, { density: 96 }); + if (req.body.transparentBackground === 'false') { + s = s.flatten({ background: { r: 255, g: 255, b: 255 } }); + } + await s.toFile(outputFileName); // Sharp's PNG type is implicitly determined via the output file extension // Convert to JPG } else { diff --git a/static/index.html b/static/index.html index b8356af..3f4f3e2 100644 --- a/static/index.html +++ b/static/index.html @@ -68,6 +68,14 @@ +
+
+ + +
+