/compass/005_compass/compass/node_modules/gm/lib/convenience/autoOrient.js |
@@ -0,0 +1,57 @@ |
|
/** |
* Extend proto. |
*/ |
|
module.exports = function (proto) { |
|
var exifTransforms = { |
topleft: '' |
, topright: ['-flop'] |
, bottomright: ['-rotate', 180] |
, bottomleft: ['-flip'] |
, lefttop: ['-flip', '-rotate', 90] |
, righttop: ['-rotate', 90] |
, rightbottom: ['-flop', '-rotate', 90] |
, leftbottom: ['-rotate', 270] |
} |
|
proto.autoOrient = function autoOrient () { |
// Always strip EXIF data since we can't |
// change/edit it. |
|
// imagemagick has a native -auto-orient option |
// so does graphicsmagick, but in 1.3.18. |
// nativeAutoOrient option enables this if you know you have >= 1.3.18 |
if (this._options.nativeAutoOrient || this._options.imageMagick) { |
this.out('-auto-orient'); |
this.strip(); |
return this; |
} |
|
this.preprocessor(function (callback) { |
this.orientation({bufferStream: true}, function (err, orientation) { |
if (err) return callback(err); |
|
var transforms = exifTransforms[orientation.toLowerCase()]; |
if (transforms) { |
|
// remove any existing transforms that might conflict |
var index = this._out.indexOf(transforms[0]); |
if (~index) { |
this._out.splice(index, transforms.length); |
} |
|
// repage to fix coordinates |
this._out.unshift.apply(this._out, transforms.concat('-page', '+0+0')); |
} |
|
this.strip(); |
|
callback(); |
}); |
}); |
|
return this; |
} |
} |
/compass/005_compass/compass/node_modules/gm/lib/convenience/morph.js |
@@ -0,0 +1,61 @@ |
|
/** |
* Module dependencies. |
*/ |
|
var fs = require('fs'); |
var parallel = require('array-parallel'); |
|
/** |
* Extend proto. |
*/ |
|
module.exports = function (proto) { |
|
/** |
* Do nothing. |
*/ |
|
function noop () {} |
|
// http://www.graphicsmagick.org/GraphicsMagick.html#details-morph |
proto.morph = function morph (other, outname, callback) { |
if (!outname) { |
throw new Error("an output filename is required"); |
} |
|
callback = (callback || noop).bind(this) |
|
var self = this; |
|
if (Array.isArray(other)) { |
other.forEach(function (img) { |
self.out(img); |
}); |
self.out("-morph", other.length); |
} else { |
self.out(other, "-morph", 1); |
} |
|
self.write(outname, function (err, stdout, stderr, cmd) { |
if (err) return callback(err, stdout, stderr, cmd); |
|
// Apparently some platforms create the following temporary files. |
// Check if the output file exists, if it doesn't, then |
// work with temporary files. |
fs.exists(outname, function (exists) { |
if (exists) return callback(null, stdout, stderr, cmd); |
|
parallel([ |
fs.unlink.bind(fs, outname + '.0'), |
fs.unlink.bind(fs, outname + '.2'), |
fs.rename.bind(fs, outname + '.1', outname) |
], function (err) { |
callback(err, stdout, stderr, cmd); |
}) |
}) |
}); |
|
return self; |
} |
} |
/compass/005_compass/compass/node_modules/gm/lib/convenience/thumb.js |
@@ -0,0 +1,92 @@ |
|
/** |
* Extend proto. |
*/ |
|
module.exports = function (proto) { |
|
proto.thumb = function thumb (w, h, name, quality, align, progressive, callback, opts) { |
var self = this, |
args = Array.prototype.slice.call(arguments); |
|
opts = args.pop(); |
|
if (typeof opts === 'function') { |
callback = opts; |
opts = ''; |
} else { |
callback = args.pop(); |
} |
|
w = args.shift(); |
h = args.shift(); |
name = args.shift(); |
quality = args.shift() || 63; |
align = args.shift() || 'topleft'; |
var interlace = args.shift() ? 'Line' : 'None'; |
|
self.size(function (err, size) { |
if (err) { |
return callback.apply(self, arguments); |
} |
|
w = parseInt(w, 10); |
h = parseInt(h, 10); |
|
var w1, h1; |
var xoffset = 0; |
var yoffset = 0; |
|
if (size.width < size.height) { |
w1 = w; |
h1 = Math.floor(size.height * (w/size.width)); |
if (h1 < h) { |
w1 = Math.floor(w1 * (((h-h1)/h) + 1)); |
h1 = h; |
} |
} else if (size.width > size.height) { |
h1 = h; |
w1 = Math.floor(size.width * (h/size.height)); |
if (w1 < w) { |
h1 = Math.floor(h1 * (((w-w1)/w) + 1)); |
w1 = w; |
} |
} else if (size.width == size.height) { |
var bigger = (w>h?w:h); |
w1 = bigger; |
h1 = bigger; |
} |
|
if (align == 'center') { |
if (w < w1) { |
xoffset = (w1-w)/2; |
} |
if (h < h1) { |
yoffset = (h1-h)/2; |
} |
} |
|
self |
.quality(quality) |
.in("-size", w1+"x"+h1) |
.scale(w1, h1, opts) |
.crop(w, h, xoffset, yoffset) |
.interlace(interlace) |
.noProfile() |
.write(name, function () { |
callback.apply(self, arguments); |
}); |
}); |
|
return self; |
}; |
|
proto.thumbExact = function () { |
var self = this, |
args = Array.prototype.slice.call(arguments); |
|
args.push('!'); |
|
self.thumb.apply(self, args); |
}; |
}; |