master
Dan Rocha 9 years ago
parent e70fcfc72d
commit 4fa2418126
  1. 5
      examples/thumb.js
  2. 11
      examples/thumbExact.js
  3. 33
      lib/convenience/thumb.js
  4. 30
      test/417.js

@ -3,10 +3,9 @@
var gm = require('../')
, dir = __dirname + '/imgs'
gm(dir + '/original.jpg')
.thumb(150, 50, dir + '/thumb.jpg', function(err){
if (err) return console.dir(arguments)
console.log(this.outname + " created :: " + arguments[3])
}
)
});

@ -0,0 +1,11 @@
// gm - Copyright Aaron Heckmann <aaron.heckmann+github@gmail.com> (MIT Licensed)
var gm = require('../')
, dir = __dirname + '/imgs'
gm(dir + '/original.jpg')
.thumbExact(150, 50, dir + '/thumb.jpg', function(err){
if (err) return console.dir(arguments)
console.log(this.outname + " created :: " + arguments[3])
});

@ -5,11 +5,19 @@
module.exports = function (proto) {
proto.thumb = function thumb (w, h, name, quality, align, progressive, callback) {
var self = this
, args = Array.prototype.slice.call(arguments);
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();
}
callback = args.pop();
w = args.shift();
h = args.shift();
name = args.shift();
@ -61,15 +69,24 @@ module.exports = function (proto) {
self
.quality(quality)
.in("-size", w1+"x"+h1)
.scale(w1, h1)
.scale(w1, h1, opts)
.crop(w, h, xoffset, yoffset)
.interlace(interlace)
.noProfile()
.write(name, function () {
callback.apply(self, arguments)
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);
};
};

@ -0,0 +1,30 @@
var assert = require('assert')
var fs = require('fs');
var path = require('path');
module.exports = function (_, dir, finish, gm) {
if (!gm.integration)
return finish();
gm(dir + '/original.jpg')
.thumb(150, 40, dir + '/thumb.png', function thumb (err) {
gm(dir + '/thumb.png')
.size(function (err, size) {
if (err) return finish(err);
assert.equal(142, size.width);
assert.equal(40, size.height);
gm(dir + '/original.jpg')
.thumbExact(150, 40, dir + '/thumb.png', function thumb (err) {
gm(dir + '/thumb.png')
.size(function (err, size) {
assert.equal(150, size.width);
assert.equal(40, size.height);
finish(err);
});
});
});
});
}
Loading…
Cancel
Save