Last active
March 17, 2020 00:19
-
-
Save lukasasorensen/fdf1b63a614e03fa94dc826d920ad5a1 to your computer and use it in GitHub Desktop.
download image from temp bucket, split into 3 sizes, and reupload to app bucket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}) | |
}) | |
}); | |
} | |
} |
@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?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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