Add option to save PNG without transparency

This commit is contained in:
Asger Hautop Drewsen 2021-04-13 10:00:47 +02:00
parent f077a800f9
commit e2c72993df
3 changed files with 15 additions and 3 deletions

7
app.js
View File

@ -97,8 +97,11 @@ conversionRouter.post('/convert', async (req, res) => {
// Convert to PNG // Convert to PNG
} else if (fileFormat === 'png') { } else if (fileFormat === 'png') {
await sharp(inputSvgFileName, { density: 96 }) let s = sharp(inputSvgFileName, { density: 96 });
.toFile(outputFileName); // Sharp's PNG type is implicitly determined via the output file extension 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 // Convert to JPG
} else { } else {

View File

@ -68,6 +68,14 @@
</label> </label>
</div> </div>
</div> </div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" id="transparentBackgroundCheckbox" checked>
<label class="form-check-label" for="transparentBackgroundCheckbox">
Transparent background (for PNG)
</label>
</div>
</div>
<button class="btn btn-primary" type="button" id="convertButton"> <button class="btn btn-primary" type="button" id="convertButton">
<span class="spinner-grow spinner-grow-sm d-none" role="status" aria-hidden="true" id="convertSpinner"></span> <span class="spinner-grow spinner-grow-sm d-none" role="status" aria-hidden="true" id="convertSpinner"></span>
<span id="convertButtonText">Convert</span> <span id="convertButtonText">Convert</span>

View File

@ -57,7 +57,8 @@ $(document).ready(function() {
data: { data: {
latexInput: latexInput, latexInput: latexInput,
outputFormat: $('#outputFormatSelect').val(), outputFormat: $('#outputFormatSelect').val(),
outputScale: $('#outputScaleSelect').val() outputScale: $('#outputScaleSelect').val(),
transparentBackground: $('#transparentBackgroundCheckbox').prop('checked'),
}, },
success: function(data) { success: function(data) {
$('#convertButton').prop('disabled', false); $('#convertButton').prop('disabled', false);