Check to ensure image format conversion was successful
This commit is contained in:
parent
0cce3abc24
commit
05d3f49621
25
app.js
25
app.js
@ -109,16 +109,21 @@ app.post('/convert', function (req, res) {
|
|||||||
finalSvgToImageCMD += ' "svg {background: white}"';
|
finalSvgToImageCMD += ' "svg {background: white}"';
|
||||||
}
|
}
|
||||||
shell.exec(finalSvgToImageCMD);
|
shell.exec(finalSvgToImageCMD);
|
||||||
|
|
||||||
// Compress the resultant image
|
// Ensure conversion was successful; eg. fails if `svgexport` or `imagemin` is not installed
|
||||||
var finalImageMinCMD = imageMinCMD.replace('IN_FILE_NAME', `${tempDirRoot}${id}/equation.${fileFormat}`);
|
if (fs.existsSync(`${tempDirRoot}${id}/equation.${fileFormat}`)) {
|
||||||
finalImageMinCMD = finalImageMinCMD.replace('OUT_FILE_NAME', `${tempDirRoot}${id}/equation_compressed.${fileFormat}`);
|
// Compress the resultant image
|
||||||
shell.exec(finalImageMinCMD);
|
var finalImageMinCMD = imageMinCMD.replace('IN_FILE_NAME', `${tempDirRoot}${id}/equation.${fileFormat}`);
|
||||||
|
finalImageMinCMD = finalImageMinCMD.replace('OUT_FILE_NAME', `${tempDirRoot}${id}/equation_compressed.${fileFormat}`);
|
||||||
// Final image
|
shell.exec(finalImageMinCMD);
|
||||||
shell.cp(`${tempDirRoot}${id}/equation_compressed.${fileFormat}`, `${outputDir}img-${id}.${fileFormat}`);
|
|
||||||
|
// Final image
|
||||||
result.imageURL = `${httpOutputURL}img-${id}.${fileFormat}`;
|
shell.cp(`${tempDirRoot}${id}/equation_compressed.${fileFormat}`, `${outputDir}img-${id}.${fileFormat}`);
|
||||||
|
|
||||||
|
result.imageURL = `${httpOutputURL}img-${id}.${fileFormat}`;
|
||||||
|
} else {
|
||||||
|
result.error = `Error converting SVG file to ${fileFormat.toUpperCase()} image.`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.error = 'Error converting LaTeX to image. Please ensure the input is valid.';
|
result.error = 'Error converting LaTeX to image. Please ensure the input is valid.';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user