Sharp: Error with SVG Input buffer on zeit/now platform

Created on 11 Dec 2017  Â·  10Comments  Â·  Source: lovell/sharp

First of all, thanks for this great and useful module!

Description

This code essentially converts an svg String into Buffer to pass as _input_ to sharp and then obtain its png _output_, works as expected.

Something like:

const src = `<svg>…</svg>`
const buff = Buffer.from(src)
sharp(buff).toBuffer().then(data => console.log(data))

Expected behaviour

Running it in my local machine works as expected:
sharp1

Local machine is Max OS X El Capital (10.11.6)

Works well also in another computer Ubuntu 16.04.3.

Problem

I am trying to deploy a _microservice_ that use at some point similar code of this reproduction, and love the simplicity of now, but when deploying it doesn't work as expected. Returns:

Error: Input buffer contains unsupported image format

sharp2

Repo

I created a repository with the simplest code I found break the functionality here: https://github.com/elrumordelaluz/sharp-test
The endpoint deployed using now is https://sharp-test.now.sh/

Please, let me know if you think is a issue related on now platform or deployment process instead if sharp.

Thanks in advance and congrats for the great work!

question

All 10 comments

Hello, this looks a bit like #979, where Buffer is being replaced/polyfilled by a runtime environment.

Are you able to test if changing instanceof Buffer to Buffer.isBuffer fixes this?

Hi @lovell, yes seems pretty similar.

I made another deploy here https://sharp-test-hkhedybbve.now.sh/ adding

const buff = Buffer.from(src)
console.log({
  instanceof: buff instanceof Buffer,
  isBuffer: Buffer.isBuffer(buff)
})

and in both cases (local and zeit/now) logs:

{ instanceof: true, isBuffer: true }

screen shot 2017-12-11 at 15 28 02

Please let me know if I can do any other thing to test, super happy to contribute.

In the last comment you ask to make some change here. You mean to make a fork and then point the repro to the forked module?

It's possible that the zeit/now platform provides a globally-installed vips that is being used. What does the following generate?

console.log(sharp.format);
console.log(sharp.versions);

https://github.com/zeit/now-cli/issues/639#issuecomment-306534497 suggests vips is made available globally to the zeit/now runtime. https://git.alpinelinux.org/cgit/aports/tree/testing/vips/APKBUILD does not include librsvg so SVG support will not currently be available.

Here's the logs:

{ jpeg: 
   { id: 'jpeg',
     input: { file: true, buffer: true, stream: true },
     output: { file: true, buffer: true, stream: true } },
  png: 
   { id: 'png',
     input: { file: true, buffer: true, stream: true },
     output: { file: true, buffer: true, stream: true } },
  webp: 
   { id: 'webp',
     input: { file: true, buffer: true, stream: true },
     output: { file: true, buffer: true, stream: true } },
  tiff: 
   { id: 'tiff',
     input: { file: true, buffer: true, stream: true },
     output: { file: true, buffer: true, stream: true } },
  magick: 
   { id: 'magick',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  openslide: 
   { id: 'openslide',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  dz: 
   { id: 'dz',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  ppm: 
   { id: 'ppm',
     input: { file: true, buffer: false, stream: false },
     output: { file: true, buffer: false, stream: false } },
  fits: 
   { id: 'fits',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  gif: 
   { id: 'gif',
     input: { file: true, buffer: true, stream: true },
     output: { file: false, buffer: false, stream: false } },
  svg: 
   { id: 'svg',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  pdf: 
   { id: 'pdf',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  v: 
   { id: 'v',
     input: { file: false, buffer: false, stream: false },
     output: { file: false, buffer: false, stream: false } },
  raw: 
   { id: 'raw',
     input: { file: false, buffer: true, stream: true },
     output: { file: false, buffer: true, stream: true } } }

{ vips: '8.5.8' }

Maybe related?

Thanks, this confirms that zeit/now provides a globally-installed libvips v8.5.8 that has been compiled without SVG support. You'll need to take this one up with them, good luck!

Thanks for your support @lovell

The version of libvips on ZEIT Now includes SVG input support now. I believe this issue can be closed.

includes SVG input support now.

I can confirm that works as expected here

Thanks @TooTallNate and @lovell

Was this page helpful?
0 / 5 - 0 ratings