Skip to content

Instantly share code, notes, and snippets.

@hackerzhut
Created July 1, 2014 02:30
Show Gist options
  • Save hackerzhut/364c31ae780597e5230d to your computer and use it in GitHub Desktop.
Save hackerzhut/364c31ae780597e5230d to your computer and use it in GitHub Desktop.
Resize image using Graphicsmagick and upload using S3
gm(request(url))
.resize("80^", "80^")
.stream(function (err, stdout, stderr) {
var chunks = [];
stdout.on('data', function (chunk) {
chunks.push(chunk);
});
stdout.on('end', function () {
var image = Buffer.concat(chunks);
var options = {
Bucket: "bucketName",
Key: "filename.png",
Body: image,
ACL: "public-read",
ContentLength: image.length,
ContentType: "image/png"
};
s3bucket.putObject(options, function (err, res) {
console.log(res);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment