ELECTRON-1161: converting from png to jpg using jimp (#615)

This commit is contained in:
VICTOR RAPHAEL BRAGA DE SALES MASCARENHAS 2019-03-28 01:45:53 -03:00 committed by Vishwas Shashidhar
parent b55da7be65
commit b591a1fe56
3 changed files with 17 additions and 7 deletions

View File

@ -4,6 +4,7 @@ const electron = require('electron');
const app = electron.app;
const childProcess = require('child_process');
const fs = require('fs');
const Jimp = require('jimp');
const os = require('os');
const path = require('path');
@ -143,12 +144,20 @@ function readResult(outputFileName, resolve, reject, childProcessErr) {
try {
// convert binary data to base64 encoded string
let output = Buffer.from(data).toString('base64');
const resultOutput = {
type: isWindowsOS ? 'image/png;base64' : 'image/jpg;base64',
data: output
};
resolve(resultOutput);
Jimp.read(outputFileName, (error, image) => {
if (error) throw error;
image.quality(100)
.getBufferAsync(Jimp.MIME_JPEG).then(src => {
const value = src.toString('base64');
const resultOutput = {
type: 'image/jpg;base64',
data: value,
};
resolve(resultOutput);
}).catch((e) => {
log.send(logLevels.ERROR, e);
});
});
} catch (error) {
reject(createError(error));
} finally {

View File

@ -118,6 +118,7 @@
"electron-spellchecker": "git+https://github.com/symphonyoss/electron-spellchecker.git#v1.1.5",
"ffi": "git+https://github.com/symphonyoss/node-ffi.git#v1.2.9",
"filesize": "3.6.1",
"jimp": "0.6.0",
"keymirror": "0.1.1",
"lodash.difference": "4.5.0",
"lodash.isequal": "4.5.0",

File diff suppressed because one or more lines are too long