Last active
February 1, 2017 10:16
don't use toBuffer.
This file contains 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
gm(imageBuffer.data).size(function(err,size){ | |
var w = 1200; | |
var h = 630; | |
if(err){ | |
console.log("gm error") | |
context.fail(err); | |
} | |
this.background("#ffffff").resize(w,h).gravity("Center").extent(w,h).stream(function(err,stdout,stderr){ | |
if(err){ | |
console.log("gm process error"); | |
console.log(err,stdout,stderr) | |
context.fail(err); | |
} | |
var chunks = []; | |
stdout.on('data',function(chunk){ | |
chunks.push(chunk); | |
}); | |
stdout.on('end',function(){ | |
var buffer = Buffer.concat(chunks); | |
var params = { | |
Bucket: BUCKET_NAME, | |
Key: "hoge/hoge.png", | |
ACL: 'public-read', | |
ContentType: imageBuffer.type, | |
Body: buffer | |
}; | |
s3.putObject(params, function(err, data) { | |
if(err){ | |
console.log("gm upload error"); | |
context.fail(err); | |
} | |
context.succeed({ | |
"error":false | |
}); | |
}); | |
}); | |
stderr.on('data',function(data){ | |
console.log(`stderr ${size} data:`, data); | |
}) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment