mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Improve SVG support by allowing control of density/DPI
Switch pre-built libs from Imagemagick to Graphicsmagick
This commit is contained in:
17
test/fixtures/Wikimedia-logo.svg
vendored
17
test/fixtures/Wikimedia-logo.svg
vendored
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" standalone="yes"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
|
||||
id="Wikimedia logo"
|
||||
viewBox="-599 -599 1198 1198" width="1024" height="1024">
|
||||
<defs>
|
||||
<clipPath id="mask">
|
||||
<path d="M 47.5,-87.5 v 425 h -95 v -425 l -552,-552 v 1250 h 1199 v -1250 z" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
<g clip-path="url(#mask)">
|
||||
<circle id="green parts" fill="#396" r="336.5"/>
|
||||
<circle id="blue arc" fill="none" stroke="#069" r="480.25" stroke-width="135.5" />
|
||||
</g>
|
||||
<circle fill="#900" cy="-379.5" r="184.5" id="red circle"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 692 B |
3
test/fixtures/check.svg
vendored
Normal file
3
test/fixtures/check.svg
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
|
||||
<path d="M30,76q6-14,13-26q6-12,14-23q8-12,13-17q3-4,6-6q1-1,5-2q8-1,12-1q1,0,1,1q0,1-1,2q-13,11-27,33q-14,21-24,44q-4,9-5,11q-1,2-9,2q-5,0-6-1q-1-1-5-6q-5-8-12-15q-3-4-3-6q0-2,4-5q3-2,6-2q3,0,8,3q5,4,10,14z" fill="green" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 301 B |
BIN
test/fixtures/expected/svg.png
vendored
BIN
test/fixtures/expected/svg.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 5.7 KiB |
BIN
test/fixtures/expected/svg1200.png
vendored
Normal file
BIN
test/fixtures/expected/svg1200.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 574 B |
BIN
test/fixtures/expected/svg72.png
vendored
Normal file
BIN
test/fixtures/expected/svg72.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 938 B |
2
test/fixtures/index.js
vendored
2
test/fixtures/index.js
vendored
@@ -84,7 +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
|
||||
inputGif: getPath('Crash_test.gif'), // http://upload.wikimedia.org/wikipedia/commons/e/e3/Crash_test.gif
|
||||
inputSvg: getPath('Wikimedia-logo.svg'), // http://commons.wikimedia.org/wiki/File:Wikimedia-logo.svg
|
||||
inputSvg: getPath('check.svg'), // http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg
|
||||
inputPsd: getPath('free-gearhead-pack.psd'), // https://dribbble.com/shots/1624241-Free-Gearhead-Vector-Pack
|
||||
|
||||
inputSvs: getPath('CMU-1-Small-Region.svs'), // http://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/CMU-1-Small-Region.svs
|
||||
|
||||
@@ -634,20 +634,37 @@ describe('Input/output', function() {
|
||||
});
|
||||
|
||||
if (sharp.format.magick.input.file) {
|
||||
it('Convert SVG, if supported, to PNG', function(done) {
|
||||
it('Convert SVG to PNG at default 72DPI', function(done) {
|
||||
sharp(fixtures.inputSvg)
|
||||
.resize(100, 100)
|
||||
.resize(1024)
|
||||
.extract({left: 290, top: 760, width: 40, height: 40})
|
||||
.toFormat('png')
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) {
|
||||
assert.strictEqual(0, err.message.indexOf('Input file is missing or of an unsupported image format'));
|
||||
done();
|
||||
} else {
|
||||
assert.strictEqual(true, info.size > 0);
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('svg.png'), data, done);
|
||||
assert.strictEqual(40, info.width);
|
||||
assert.strictEqual(40, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('svg72.png'), data, done);
|
||||
}
|
||||
});
|
||||
});
|
||||
it('Convert SVG to PNG at 300DPI', function(done) {
|
||||
sharp(fixtures.inputSvg, { density: 1200 })
|
||||
.resize(1024)
|
||||
.extract({left: 290, top: 760, width: 40, height: 40})
|
||||
.toFormat('png')
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) {
|
||||
assert.strictEqual(0, err.message.indexOf('Input file is missing or of an unsupported image format'));
|
||||
done();
|
||||
} else {
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(40, info.width);
|
||||
assert.strictEqual(40, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('svg1200.png'), data, done);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -824,6 +841,27 @@ describe('Input/output', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('Input options', function() {
|
||||
it('Non-Object options fails', function() {
|
||||
assert.throws(function() {
|
||||
sharp(null, 'zoinks');
|
||||
});
|
||||
});
|
||||
it('Invalid density: string', function() {
|
||||
assert.throws(function() {
|
||||
sharp(null, { density: 'zoinks' } );
|
||||
});
|
||||
});
|
||||
it('Invalid density: float', function() {
|
||||
assert.throws(function() {
|
||||
sharp(null, { density: 0.5 } );
|
||||
});
|
||||
});
|
||||
it('Ignore unknown attribute', function() {
|
||||
sharp(null, { unknown: true } );
|
||||
});
|
||||
});
|
||||
|
||||
it('Queue length change events', function(done) {
|
||||
var eventCounter = 0;
|
||||
var queueListener = function(queueLength) {
|
||||
|
||||
Reference in New Issue
Block a user