Add background and flatten APIs

This commit is contained in:
Daniel Gasienica
2014-09-12 19:53:58 -07:00
parent 513b07ddcf
commit 6145231936
6 changed files with 164 additions and 15 deletions

View File

@@ -546,6 +546,15 @@ async.series([
done();
});
},
function(done) {
sharp(inputPngWithTransparency).resize(320, 80).toFile(outputZoinks, function(err, info) {
if (err) throw err;
assert.strictEqual('png', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(80, info.height);
done();
});
},
function(done) {
sharp(inputWebP).resize(320, 80).toFile(outputZoinks, function(err, info) {
if (err) throw err;
@@ -742,6 +751,42 @@ async.series([
done();
});
},
// Flattening
function(done) {
sharp(inputPngWithTransparency).flatten().resize(400, 300).toFile(path.join(fixturesPath, 'output.flatten-black.jpg'), function(err) {
if (err) throw err;
done();
});
},
function(done) {
sharp(inputPngWithTransparency).flatten().background(255, 102, 0).resize(400, 300).toFile(path.join(fixturesPath, 'output.flatten-rgb-orange.jpg'), function(err) {
if (err) throw err;
done();
});
},
function(done) {
sharp(inputPngWithTransparency).flatten().background('#ff6600').resize(400, 300).toFile(path.join(fixturesPath, 'output.flatten-hex-orange.jpg'), function(err) {
if (err) throw err;
done();
});
},
function(done) {
sharp(inputJpg).background('#ff0000').flatten().resize(500, 400).toFile(path.join(fixturesPath, 'output.flatten-input-jpg.jpg'), function(err) {
if (err) throw err;
done();
});
},
function(done) {
// Invalid `background` arguments
try {
sharp(inputPngWithTransparency).background(-1, -1, -1).flatten();
} catch (e) {
assert.strictEqual(e.message, "Invalid red value (0.0 to 255.0) -1");
done();
return;
}
assert.fail();
},
// Verify internal counters
function(done) {
var counters = sharp.counters();