Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG streams without xml, DOCTYPE headers aren't supported #356

Closed
makepanic opened this issue Feb 8, 2016 · 5 comments
Closed

SVG streams without xml, DOCTYPE headers aren't supported #356

makepanic opened this issue Feb 8, 2016 · 5 comments
Labels

Comments

@makepanic
Copy link

sharp streams currently only support svg images with the xml + DOCTYPE headers `

`

Is it possible to add svg support for streams that omit these headers and only use the <svg> element?

Example:
wikimedia-with-header.svg

<?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" viewBox="0 0 100 100">
  <path d="M19,16a46,46 0,1,0 62,0l-8,8a34,34 0,1,1-46,0z" fill="#069"/>
  <path d="M46,43v35a28,28 0,0,1-14-49zM54,43v35a28,28 0,0,0 14-49z" fill="#396"/>
  <circle r="15" cx="50" cy="18" fill="#900"/>
</svg>

wikimedia-without-header.svg

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <path d="M19,16a46,46 0,1,0 62,0l-8,8a34,34 0,1,1-46,0z" fill="#069"/>
  <path d="M46,43v35a28,28 0,0,1-14-49zM54,43v35a28,28 0,0,0 14-49z" fill="#396"/>
  <circle r="15" cx="50" cy="18" fill="#900"/>
</svg>

Sample code to reproduce:

var fs = require('fs'),
    path = require('path'),
    sharp = require('sharp');

var WITH_HEADER = path.join(__dirname, 'wikimedia-with-header.svg'),
    WITHOUT_HEADER = path.join(__dirname, 'wikimedia-without-header.svg');

var withheaderStream = fs.createReadStream(WITH_HEADER),
    withoutHeaderStream = fs.createReadStream(WITHOUT_HEADER);

function buildConvertPipe() {
    return sharp().rotate()
        .background('white').flatten()
        .toFormat('jpeg')
        .resize(200, 200)
        .min()
        .crop(sharp.gravity.center)
}

var withHeaderPipe = withheaderStream
    .pipe(buildConvertPipe());
withHeaderPipe.on('error', function () {
    console.log('with header stream failed.');
});
withHeaderPipe.pipe(fs.createWriteStream(WITH_HEADER + '.with-header.jpeg'));


var withoutHeaderPipe = withoutHeaderStream
    .pipe(buildConvertPipe());

withoutHeaderPipe.on('error', function () {
    console.log('without header stream failed.');
});
withoutHeaderPipe.pipe(fs.createWriteStream(WITH_HEADER + '.without-header.jpeg'));

which produces
20160208-150211

probably related to #197

@lovell
Copy link
Owner

lovell commented Feb 8, 2016

Hello, this looks like a limitation of ImageMagick's built-in SVG parser, as (optionally) used by libvips to handle SVGs.

You'll probably have more success if you use libvips compiled against GraphicsMagick.

The pre-compiled binaries provided by sharp will be switching to GraphicsMagick for Linux users from the next release. If you're using Linux, are you able to try using the master branch via npm install lovell/sharp?

@lovell lovell added the question label Feb 8, 2016
@makepanic
Copy link
Author

I tried to run it in a ubuntu docker instance that uses the current preinstall.sh script (+ gm and imagemagick from source) and npm installes lovell/sharp. It's still failing for the svg without xml header. (getting segfaults on local arch, which are probably unrelated)

Is there something else i could try or do i have to specify some build flags to build libvips against gm?

@lovell
Copy link
Owner

lovell commented Feb 8, 2016

As of sharp v0.12.0, the preinstall script is no longer required for most flavours of Linux, including Ubuntu 12.04+

Are you able to try installing from the master branch without?

@lovell
Copy link
Owner

lovell commented Feb 22, 2016

@makepanic v0.13.0 is out now - have you been able to make any progress with this?

@lovell
Copy link
Owner

lovell commented Mar 11, 2016

Closing as I assume v0.13.x has solved this problem. Feel free to reopen if this is not the case.

@lovell lovell closed this as completed Mar 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants