sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Loading vector formats (PDF, EPS, SVG, etc.)

Open mindplay-dk opened this issue 4 months ago • 1 comments

Question about an existing feature

What are you trying to achieve?

I'm trying to load vector formats, such as PDF, EPS or SVG, to generate thumbnails.

When you searched for similar issues, what did you find that might be related?

It looks like there is some degree of support for PDF already?

I see some issues like #3321 and others talking about PDF related features - although there is no mention of PDF support (or any vector formats) in the docs or on the home page.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

sharp('input.eps', { page: 1, density: 72 })
  .jpeg({ quality: 75 })
  .toFile('output.jpg', (err, info) => {
    console.log(err);
  });

This will error with Input file contains unsupported image format, since EPS is not supported.

I do believe the underlying libvips is capable of loading various vector formats?

Are there any known good workarounds for vector format support?

mindplay-dk avatar Feb 19 '24 08:02 mindplay-dk

The prebuilt libvips binaries provided by sharp include support for SVG input.

For PDF or EPS support you'll need to install libvips globally first, then re-install/build sharp from source.

For PDF input, libvips will need to be compiled with poppler or pdfium support. For EPS input, libvips will need to be compiled with ImageMagick support.

https://sharp.pixelplumbing.com/install#custom-libvips https://sharp.pixelplumbing.com/install#building-from-source https://www.libvips.org/install.html#building-libvips-from-source https://github.com/libvips/libvips#optional-dependencies

lovell avatar Feb 19 '24 09:02 lovell

@mindplay-dk Were you able to make any progress with this?

lovell avatar Mar 23 '24 17:03 lovell

No, I don't know C++ and I'm not adventurous enough to build it from source.

Thanks though. 🙂

mindplay-dk avatar Mar 24 '24 09:03 mindplay-dk

No worries. If you've not already done so, perhaps investigate the various command line tools provided by Ghostscript and/or Poppler.

lovell avatar Mar 24 '24 13:03 lovell

is there any reason why PDF and EPS support don't just ship with the prebuilt binary?

(file size is not a real big issue these days, is it?)

mindplay-dk avatar Mar 26 '24 14:03 mindplay-dk

It's about providing what most people need most of the time; one cannot please everyone all the time.

File size is often an issue for those using edge compute platforms. GPL licensing is often an issue for those distributing apps.

sharp will always provide the ability to use a custom, globally-installed libvips compiled with support for additional or more specific dependencies.

lovell avatar Mar 26 '24 15:03 lovell