mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose WebP alpha quality, lossless and near-lossless output options (#685)
This commit is contained in:
committed by
Lovell Fuller
parent
815d076b35
commit
a1b8efe721
BIN
test/fixtures/expected/webp-alpha-80.webp
vendored
Normal file
BIN
test/fixtures/expected/webp-alpha-80.webp
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
BIN
test/fixtures/expected/webp-lossless.webp
vendored
Normal file
BIN
test/fixtures/expected/webp-lossless.webp
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 170 KiB |
BIN
test/fixtures/expected/webp-near-lossless-50.webp
vendored
Normal file
BIN
test/fixtures/expected/webp-near-lossless-50.webp
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
@@ -372,6 +372,50 @@ describe('Input/output', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for webp alpha quality', function (done) {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({alphaQuality: 80})
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('webp-alpha-80.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for webp lossless', function (done) {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({lossless: true})
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
assert.strictEqual('webp', info.format);
|
||||
fixtures.assertSimilar(fixtures.expected('webp-lossless.webp'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should work for webp near-lossless', function (done) {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({nearLossless: true, quality: 50})
|
||||
.toBuffer(function (err50, data50, info50) {
|
||||
if (err50) throw err50;
|
||||
assert.strictEqual(true, data50.length > 0);
|
||||
assert.strictEqual('webp', info50.format);
|
||||
fixtures.assertSimilar(fixtures.expected('webp-near-lossless-50.webp'), data50, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('should use near-lossless when both lossless and nearLossless are specified', function (done) {
|
||||
sharp(fixtures.inputPngAlphaPremultiplicationSmall)
|
||||
.webp({nearLossless: true, quality: 50, lossless: true})
|
||||
.toBuffer(function (err50, data50, info50) {
|
||||
if (err50) throw err50;
|
||||
assert.strictEqual(true, data50.length > 0);
|
||||
assert.strictEqual('webp', info50.format);
|
||||
fixtures.assertSimilar(fixtures.expected('webp-near-lossless-50.webp'), data50, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
it('Invalid output format', function (done) {
|
||||
@@ -735,6 +779,12 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid WebP alpha quality throws error', function () {
|
||||
assert.throws(function () {
|
||||
sharp().webp({ alphaQuality: 101 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid TIFF quality throws error', function () {
|
||||
assert.throws(function () {
|
||||
sharp().tiff({ quality: 101 });
|
||||
|
||||
Reference in New Issue
Block a user