Add option to save PNG without transparency
This commit is contained in:
parent
f077a800f9
commit
e2c72993df
7
app.js
7
app.js
@ -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 {
|
||||||
|
@ -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>
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user