Created
March 8, 2015 03:36
-
-
Save aaronthorp/c8dd1ac4975792855f7b to your computer and use it in GitHub Desktop.
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
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