Skip to content

Instantly share code, notes, and snippets.

@mr-wildcard
Created March 17, 2015 00:00
Show Gist options
  • Save mr-wildcard/5b057fe62375b2b4d14a to your computer and use it in GitHub Desktop.
Save mr-wildcard/5b057fe62375b2b4d14a to your computer and use it in GitHub Desktop.
var assert = require('assert')
module.exports = function (_, dir, next, gm) {
if (!gm.integration) return next();
var alphaTypes = [
"Activate",
"On",
"Associate",
"Deactivate",
"Off",
"Disassociate",
"Set",
"Opaque",
"Transparent",
"Extract",
"Copy",
"Shape",
"Remove",
"Background"
];
assert.throws(function() {
gm(dir + '/alpha.png')
.alpha( alphaTypes.pop() )
.write(dir + '/alpha_fail.png', function(err) {
if (!err) next( new Error('Method -alpha is supposed to fail without ImageMagick option enabled.') );
else {
nextAlpha();
}
});
}, Error);
function nextAlpha() {
test(alphaTypes.pop());
}
function test(alphaType) {
var m = gm(dir + '/alpha.png')
.options({ imageMagick: true })
.alpha( alphaType );
var args = m.args();
assert.equal('convert', args[0]);
assert.equal('-alpha', args[2]);
assert.equal(alphaType, args[3]);
m.write( dir + '/alpha_' + alphaType + '.png', function(err) {
if (!err) next(err);
else {
if (alphaTypes.length) {
nextAlpha();
} else {
next();
}
}
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment