diff --git a/lib/input.js b/lib/input.js index a3ca117e..dbb42406 100644 --- a/lib/input.js +++ b/lib/input.js @@ -57,10 +57,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) { } // Density if (is.defined(inputOptions.density)) { - if (is.inRange(inputOptions.density, 1, 2400)) { + if (is.inRange(inputOptions.density, 1, 100000)) { inputDescriptor.density = inputOptions.density; } else { - throw is.invalidParameterError('density', 'number between 1 and 2400', inputOptions.density); + throw is.invalidParameterError('density', 'number between 1 and 100000', inputOptions.density); } } // limitInputPixels diff --git a/test/fixtures/circle.svg b/test/fixtures/circle.svg new file mode 100644 index 00000000..7807e32f --- /dev/null +++ b/test/fixtures/circle.svg @@ -0,0 +1,3 @@ + + + diff --git a/test/fixtures/expected/circle.png b/test/fixtures/expected/circle.png new file mode 100644 index 00000000..9b4575ac Binary files /dev/null and b/test/fixtures/expected/circle.png differ diff --git a/test/fixtures/index.js b/test/fixtures/index.js index dab08814..28d0293e 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -107,6 +107,7 @@ module.exports = { inputGifAnimated: getPath('rotating-squares.gif'), // CC0 https://loading.io/spinner/blocks/-rotating-squares-preloader-gif inputGifAnimatedLoop3: getPath('animated-loop-3.gif'), // CC-BY-SA-4.0 Petrus3743 https://commons.wikimedia.org/wiki/File:01-Goldener_Schnitt_Formel-Animation.gif inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg + inputSvgSmallViewBox: getPath('circle.svg'), inputSvgWithEmbeddedImages: getPath('struct-image-04-t.svg'), // https://dev.w3.org/SVG/profiles/1.2T/test/svg/struct-image-04-t.svg inputJPGBig: getPath('flowers.jpeg'), diff --git a/test/unit/io.js b/test/unit/io.js index ad19964f..0e1a3f78 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -647,7 +647,7 @@ describe('Input/output', function () { it('Invalid density: string', function () { assert.throws(function () { sharp({ density: 'zoinks' }); - }, /Expected number between 1 and 2400 for density but received zoinks of type string/); + }, /Expected number between 1 and 100000 for density but received zoinks of type string/); }); it('Setting animated property updates pages property', function () { assert.strictEqual(sharp({ animated: false }).options.input.pages, 1); diff --git a/test/unit/svg.js b/test/unit/svg.js index afeff85f..300e5c2b 100644 --- a/test/unit/svg.js +++ b/test/unit/svg.js @@ -48,6 +48,31 @@ describe('SVG input', function () { }); }); + it('Convert SVG to PNG at DPI larger than 2400', function (done) { + const size = 1024; + sharp(fixtures.inputSvgSmallViewBox).metadata(function (err, metadata) { + if (err) throw err; + const density = (size / Math.max(metadata.width, metadata.height)) * metadata.density; + sharp(fixtures.inputSvgSmallViewBox, { density }) + .resize(size) + .toFormat('png') + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('png', info.format); + assert.strictEqual(size, info.width); + assert.strictEqual(size, info.height); + fixtures.assertSimilar(fixtures.expected('circle.png'), data, function (err) { + if (err) throw err; + sharp(data).metadata(function (err, info) { + if (err) throw err; + assert.strictEqual(9216, info.density); + done(); + }); + }); + }); + }); + }); + it('Convert SVG to PNG at 14.4DPI', function (done) { sharp(fixtures.inputSvg, { density: 14.4 }) .toFormat('png')