Skip to content

Instantly share code, notes, and snippets.

@aaronthorp
Created March 8, 2015 03:36
Show Gist options
  • Save aaronthorp/c8dd1ac4975792855f7b to your computer and use it in GitHub Desktop.
Save aaronthorp/c8dd1ac4975792855f7b to your computer and use it in GitHub Desktop.
var createThumb = function(fileObj, readStream, writeStream) {
var finalImageSize = 320;
var orig = gm(readStream, fileObj.name())
console.log("transforming");
orig.size(function(err, size) {
console.log(size,err); /// <<<--- this is the only place i can get the dimensions to cut crop
});
console.log(size);
if (size.width > size.height) {
cropSize = size.height;
yCrop = 0;
xCrop = (parseInt(size.width) - cropSize) / 2;
} else {
cropSize = size.width;
xCrop = 0;
yCrop = (parseInt(size.height) - cropSize) / 2;
}
var cropped = orig.crop(cropSize, cropSize, xCrop, yCrop);
var resized = cropped.resize(finalImageSize, finalImageSize);
resized.stream().pipe(writeStream);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment