question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

requiring sharp breaks ghostscript4js

See original GitHub issue

This was a wild ride to figure out. We’re using ghostscript4js to extract JPEGs from multi-page PDFs. This worked for most files until we had a file where the text of a single PDF would be complete garbage inside the JPEG. For legal reasons I am not able to share the specific PDF, but here’s the comparison of PDF vs JPEG

JPEG extracted without sharp required:

selection_273

JPEG extract with sharp required (but not used at all):

selection_274

This is a minimal test-case to reproduce (if you had the PDF…)

//Uncomment this line to break JPEG extraction.
//require('sharp');

const gs = require('ghostscript4js');

async function pdf() {
  try {
    const command =
      '-psconv -q -r300 -sPAPERSIZE=a4 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseTrimBox -sDEVICE=jpeg -dDownScaleFactor=3 -o out-%d.jpg -dJPEGQ=100 -f in.pdf';
    await gs.execute(command);
    console.log('done');
  } catch (err) {
    console.error(err);
  }
}

pdf();

Basically I’m hoping one of the maintainers has an idea as to why simply requiring sharp would break ghostscript? I’m confused af. What exactly does sharp change about the process environment that could cause something like that?

I will spend some time narrowing this down further but I’m hoping one of you knows what’s up.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, May 30, 2018

“As far as I can tell neither libfontconfig nor libfreetype are a dependency of libvips. Why are they downloaded?”

libfreetype is a dependency of libfontconfig, which is a dependency of librsvg, which is a dependency of the pre-compiled libvips provided by sharp.

“I believe the versions that sharp installs are the most recent? If so then sooner or later our PDF will break again if the global version (the apt packages are probably a bit behind) reach that version?”

The pre-compiled binaries of libvips and its dependencies are defined in https://github.com/lovell/sharp-libvips/ and are tagged against the relevant libvips version, e.g. v8.6.1. When using pre-compiled binaries, the list of versions are also made available at runtime via sharp.versions.

It sounds like the underlying problem might be a change in behaviour in libfreetype, either intentional or a regression, between its versions.

0reactions
Prinzhorncommented, May 30, 2018

Thank you for the explanation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requiring sharp · Issue #107 · vercel/pkg - GitHub
After a bit of digging in the sharp library, it turns out the problem is generated by requiring the sharp.node itself.
Read more >
Sharp JS Dependency breaks Express Server on Elastic ...
I have an ExpressJS/node server deployed to AWS Elastic Beanstalk. When I first tried to deploy several weeks ago, I couldn't get it...
Read more >
node-gyp | Yarn - Package Manager
Configuring Python Dependency. node-gyp requires that you have installed a compatible version of Python, one of: v3.7, v3.8, v3.9, or v3.10. If you...
Read more >
ghostscript4js - npm
Start using ghostscript4js in your project by running `npm i ghostscript4js`. There are 4 other projects in the npm registry using ...
Read more >
Changelog - High performance Node.js image processing
Drop support for Node.js 12, now requires Node.js >= 14.15.0. ... Allow compilation on FreeBSD and variants (broken since v0.23.0) #1952 @pouya-eghbali.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found