mirror of https://gitgud.io/fatchan/gm
it actually does something helpful now :) we may call append with string arguments, each being another image to append to the original source image. if a boolean `true` is passed, the images will be appended left-to-right, otherwise top-to-bottom. Examples: img = gm(src); // +append means left-to-right img.append(img1, img2) gm convert src img1 img2 -append img.append(img, true) gm convert src img +append img.append(img, false) gm convert src img -append img.append(img) gm convert src img -append img.append(img).append() gm convert src img -append img.append(img).append(true) gm convert src img +append img.append(img).background("#222") gm convert src img -background #222 +append fixes #77master
parent
9e58e84307
commit
7c20e1327b
6 changed files with 160 additions and 8 deletions
@ -0,0 +1,17 @@ |
||||
var gm = require('../') |
||||
, dir = __dirname + '/imgs' |
||||
, imgs = 'lost.png original.jpg'.split(' ').map(function (img) { |
||||
return dir + '/' + img |
||||
}) |
||||
, out = dir + '/append.jpg' |
||||
|
||||
gm(imgs[0]) |
||||
.append(imgs[1]) |
||||
.append() |
||||
.background('#222') |
||||
.write(out, function (err) { |
||||
if (err) return console.dir(arguments) |
||||
console.log(this.outname + " created :: " + arguments[3]) |
||||
require('child_process').exec('open ' + out) |
||||
}); |
||||
|
@ -0,0 +1,42 @@ |
||||
var assert = require('assert') |
||||
var out; |
||||
|
||||
module.exports = function (_, dir, next, gm) { |
||||
out = require('path').resolve(dir + '/append.jpg'); |
||||
|
||||
try { |
||||
require('fs').unlinkSync(out); |
||||
} catch (_) {} |
||||
|
||||
gm(dir + '/lost.png') |
||||
.append(dir + '/original.jpg') |
||||
.append() |
||||
.background('#222') |
||||
.write(out, function (err) { |
||||
if (err) return next(err); |
||||
gm(out).size(function (err, size) { |
||||
if (err) return next(err); |
||||
assert.equal(460, size.width); |
||||
assert.equal(280, size.height); |
||||
|
||||
horizontal(dir, next, gm); |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
function horizontal (dir, next, gm) { |
||||
|
||||
gm(dir + '/original.jpg') |
||||
.append(dir + '/lost.png', true) |
||||
.write(out, function (err) { |
||||
if (err) return next(err); |
||||
gm(out).size(function (err, size) { |
||||
if (err) return next(err); |
||||
assert.equal(697, size.width); |
||||
assert.equal(155, size.height); |
||||
|
||||
next(); |
||||
}) |
||||
}); |
||||
|
||||
} |
Loading…
Reference in new issue