mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Switch to libvips' resize, make fastShrinkOnLoad optional (#977)
This commit is contained in:
committed by
Lovell Fuller
parent
ebc2a741f6
commit
d0f66c3734
BIN
test/fixtures/centered_image.jpeg
vendored
Normal file
BIN
test/fixtures/centered_image.jpeg
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
BIN
test/fixtures/expected/embed-4-into-4.png
vendored
BIN
test/fixtures/expected/embed-4-into-4.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 670 B After Width: | Height: | Size: 392 B |
BIN
test/fixtures/expected/fast-shrink-on-load-false.png
vendored
Normal file
BIN
test/fixtures/expected/fast-shrink-on-load-false.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 257 B |
BIN
test/fixtures/expected/fast-shrink-on-load-true.png
vendored
Normal file
BIN
test/fixtures/expected/fast-shrink-on-load-true.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 263 B |
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@@ -67,6 +67,7 @@ module.exports = {
|
||||
inputJpg320x240: getPath('320x240.jpg'), // http://www.andrewault.net/2010/01/26/create-a-test-pattern-video-with-perl/
|
||||
inputJpgOverlayLayer2: getPath('alpha-layer-2-ink.jpg'),
|
||||
inputJpgTruncated: getPath('truncated.jpg'), // head -c 10000 2569067123_aca715a2ee_o.jpg > truncated.jpg
|
||||
inputJpgCenteredImage: getPath('centered_image.jpeg'),
|
||||
|
||||
inputPng: getPath('50020484-00001.png'), // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
|
||||
inputPngWithTransparency: getPath('blackbug.png'), // public domain
|
||||
|
||||
@@ -98,6 +98,7 @@ describe('Partial image extraction', function () {
|
||||
sharp(fixtures.inputPngWithGreyAlpha)
|
||||
.extract({ left: 20, top: 10, width: 380, height: 280 })
|
||||
.rotate(90)
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(280, info.width);
|
||||
|
||||
@@ -48,11 +48,12 @@ describe('Gamma correction', function () {
|
||||
sharp(fixtures.inputPngOverlayLayer1)
|
||||
.resize(320)
|
||||
.gamma()
|
||||
.jpeg()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
fixtures.assertSimilar(fixtures.expected('gamma-alpha.jpg'), data, { threshold: 20 }, done);
|
||||
fixtures.assertSimilar(fixtures.expected('gamma-alpha.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -448,4 +448,34 @@ describe('Resize dimensions', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('fastShrinkOnLoad: false ensures image is not shifted', function (done) {
|
||||
return sharp(fixtures.inputJpgCenteredImage)
|
||||
.resize(9, 8, {
|
||||
fastShrinkOnLoad: false,
|
||||
centreSampling: true
|
||||
})
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(9, info.width);
|
||||
assert.strictEqual(8, info.height);
|
||||
// higher threshold makes it pass for both jpeg and jpeg-turbo libs
|
||||
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-false.png'), data, { threshold: 7 }, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('fastShrinkOnLoad: true (default) might result in shifted image', function (done) {
|
||||
return sharp(fixtures.inputJpgCenteredImage)
|
||||
.resize(9, 8, {
|
||||
centreSampling: true
|
||||
})
|
||||
.png()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(9, info.width);
|
||||
assert.strictEqual(8, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('fast-shrink-on-load-true.png'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user