mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose TIFF compression and predictor options (#738)
This commit is contained in:
committed by
Lovell Fuller
parent
5e015cc3ca
commit
f8e72f443d
2
test/fixtures/index.js
vendored
2
test/fixtures/index.js
vendored
@@ -84,6 +84,7 @@ module.exports = {
|
||||
inputWebPWithTransparency: getPath('5_webp_a.webp'), // http://www.gstatic.com/webp/gallery3/5_webp_a.webp
|
||||
inputTiff: getPath('G31D.TIF'), // http://www.fileformat.info/format/tiff/sample/e6c9a6e5253348f4aef6d17b534360ab/index.htm
|
||||
inputTiffCielab: getPath('cielab-dagams.tiff'), // https://github.com/lovell/sharp/issues/646
|
||||
inputTiffUncompressed: getPath('uncompressed_tiff.tiff'), // https://code.google.com/archive/p/imagetestsuite/wikis/TIFFTestSuite.wiki file: 0c84d07e1b22b76f24cccc70d8788e4a.tif
|
||||
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
||||
inputGifGreyPlusAlpha: getPath('grey-plus-alpha.gif'), // http://i.imgur.com/gZ5jlmE.gif
|
||||
inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg
|
||||
@@ -102,6 +103,7 @@ module.exports = {
|
||||
outputPng: getPath('output.png'),
|
||||
outputWebP: getPath('output.webp'),
|
||||
outputV: getPath('output.v'),
|
||||
outputTiff: getPath('output.tiff'),
|
||||
outputZoinks: getPath('output.zoinks'), // an 'unknown' file extension
|
||||
|
||||
// Path for tests requiring human inspection
|
||||
|
||||
BIN
test/fixtures/uncompressed_tiff.tiff
vendored
Normal file
BIN
test/fixtures/uncompressed_tiff.tiff
vendored
Normal file
Binary file not shown.
124
test/unit/io.js
124
test/unit/io.js
@@ -861,6 +861,130 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF lzw compression with horizontal predictor shrinks test file', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
compression: 'lzw',
|
||||
force: true,
|
||||
// note: lzw compression is imperfect and sometimes
|
||||
// generates larger files, as it does with this input
|
||||
// if no predictor is used.
|
||||
predictor: 'horizontal'
|
||||
})
|
||||
.toFile(fixtures.outputTiff, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert(info.size < startSize);
|
||||
fs.unlinkSync(fixtures.outputTiff);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF deflate compression with hoizontal predictor shrinks test file', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
compression: 'deflate',
|
||||
force: true,
|
||||
predictor: 'horizontal'
|
||||
})
|
||||
.toFile(fixtures.outputTiff, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert(info.size < startSize);
|
||||
fs.unlinkSync(fixtures.outputTiff);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF deflate compression without predictor shrinks test file', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
compression: 'deflate',
|
||||
force: true,
|
||||
predictor: 'none'
|
||||
})
|
||||
.toFile(fixtures.outputTiff, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert(info.size < startSize);
|
||||
fs.unlinkSync(fixtures.outputTiff);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF jpeg compression shrinks test file', function (done) {
|
||||
const startSize = fs.statSync(fixtures.inputTiffUncompressed).size;
|
||||
sharp(fixtures.inputTiffUncompressed)
|
||||
.tiff({
|
||||
compression: 'jpeg',
|
||||
force: true
|
||||
})
|
||||
.toFile(fixtures.outputTiff, (err, info) => {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('tiff', info.format);
|
||||
assert(info.size < startSize);
|
||||
fs.unlinkSync(fixtures.outputTiff);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF none compression does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().tiff({ compression: 'none' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF lzw compression does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().tiff({ compression: 'lzw' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF deflate compression does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().tiff({ compression: 'deflate' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid compression option throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp().tiff({ compression: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid compression option throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp().tiff({ compression: 'a' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF invalid predictor option throws', function () {
|
||||
assert.throws(function () {
|
||||
sharp().tiff({ predictor: 'a' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF horizontal predictor does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().tiff({ predictor: 'horizontal' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF float predictor does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().tiff({ predictor: 'float' });
|
||||
});
|
||||
});
|
||||
|
||||
it('TIFF none predictor does not throw error', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
sharp().tiff({ predictor: 'none' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Input and output formats match when not forcing', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
|
||||
Reference in New Issue
Block a user