-
-
Save lukasasorensen/fdf1b63a614e03fa94dc826d920ad5a1 to your computer and use it in GitHub Desktop.
processImage(params) { | |
console.log('imageProcess.processImage params: ', JSON.stringify(params)); | |
let key = params.key; | |
let imageData; | |
let bucketForUpload = 'app-' + serverConf.nodeEnv; | |
if(key){ | |
var sizes = [50, 200, 800]; | |
const storage = new AWS.S3(); | |
var fn = function process(size) { | |
return new Promise(function (resolve, reject) { | |
var width = size; | |
var height = size; | |
gm(imageData) | |
.setFormat('jpg') | |
.antialias(true) | |
.density(300) | |
.resize(width, height) | |
.stream(function (err, stdout, stderr) { | |
var data = { | |
Bucket: bucketForUpload, | |
Key: key.split('.')[0] + '_' + size + '.jpg', | |
Body: stdout, | |
ACL: 'public-read' | |
}; | |
storage.upload(data, function(err, res) { | |
if(err){ | |
return reject(err); | |
}else{ | |
return resolve(res); | |
} | |
}); | |
}) | |
}) | |
}; | |
return new Promise(function (resolve, reject) { | |
storage.getObject({ | |
Bucket: s3Config.bucket, | |
Key: key | |
}, function(err, res){ | |
if(err){return reject(err)} | |
resolve(res) | |
}) | |
}).then((res: any) => { | |
imageData = res.Body; | |
var actions = sizes.map(fn); | |
var results = Promise.all(actions); | |
return new Promise(function(resolve, reject){ | |
results.then(data => { | |
console.log('graphics magick date = '+ JSON.stringify(data)); | |
resolve(data); | |
}) | |
}) | |
}); | |
} | |
} |
@charles1971 it seems that you are right, you can do this. https://stackoverflow.com/questions/45039779/how-to-install-imagemagick-inside-of-electron-app -- note: graphicsmagick is just a fork of imagemagick
@lukasasorensen Yes. But it looks pretty complicated:
https://github.com/joeherold/imagemagick-darwin-static
https://github.com/SamirL/graphicsmagick-static
Other:
The problem is, I don’t know where I would write the code for the first two links above. The imagemagick-darwin-static doesn’t say where I should write this code. I am writing the app in TypeScript. I have dropped the Angular option, because it was preventing IPC calls from working properly.
I have an app.js which opens the Chromium and then I have a service inside src/app, which sets up the IPC messaging system.
I guess I should put the GraphicksMagick stuff in the app.js?
@lukasasorensen I think the answer maybe yes:
https://stackoverflow.com/questions/35819200/nodejs-electron-confusion-about-client-server-code
But, it is still not 100% clear. I know that Electron can definitely access the client’s file system.