Skip to content

Commit

Permalink
add resize and crop option
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Sep 8, 2012
1 parent b0c1509 commit fcc1604
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/imager.js
Expand Up @@ -100,6 +100,15 @@ Imager.prototype.startUpload = function (file, filename, variant, iteratorCallba
}) })
} }


if (variants.resizeAndCrop) {
Object.keys(variants.resizeAndCrop).forEach(function (name) {
var processFiles = function (cb) {
self.resizeAndCropFile(file, { name: name, type: variants.resizeAndCrop[name] }, filename, cb)
}
asyncArr.push(processFiles)
})
}

async.parallel(asyncArr, function (err, results) { async.parallel(asyncArr, function (err, results) {
if (err) console.log(err) if (err) console.log(err)
var f = _.uniq(results).toString() var f = _.uniq(results).toString()
Expand Down Expand Up @@ -151,6 +160,27 @@ Imager.prototype.cropFile = function (file, preset, fname, cb) {
} }




Imager.prototype.resizeAndCropFile = function (file, preset, fname, cb) {
var ct = { 'image/jpeg': '.jpg', 'image/png': '.png', 'image/gif': '.gif' }
, fileType = ct[file['type']]
, filename = fname + fileType
, self = this

var remoteFile = preset.name + '_' + filename
, dest = '/tmp/' + remoteFile

gm(file['path'])
.resize(preset.type.resize.split('x')[0], preset.type.resize.split('x')[1])
.gravity('Center')
.crop(preset.type.crop.split('x')[0], preset.type.crop.split('x')[1])
.write(dest, function(err) {
if (err) return cb(err)
self['pushTo' + self.storage](dest, remoteFile, filename, file['type'], cb)
}
)
}


Imager.prototype.pushToRackspace = function (file, remoteFile, filename, type, cb) { Imager.prototype.pushToRackspace = function (file, remoteFile, filename, type, cb) {
var self = this var self = this
, client = cloudfiles.createClient(this.config['storage'][this.storage]) , client = cloudfiles.createClient(this.config['storage'][this.storage])
Expand Down

0 comments on commit fcc1604

Please sign in to comment.