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.

Expose setting xres/yres for JPEG/PNG output

See original GitHub issue

Hi!

I saw that in the documentation it is possible to adjust the density metadata in the constructor, but it doesn’t work in my case for some reason. Below is the code which works but the density is never adjusted. Does anyone know how I can do this with the code snippet below?

Thanks!

const sharpImage = sharp(imagedData /* tried adding density here ... , {density: 170} */)
      sharpImage
      .rotate()
      .metadata()
      .then(function(metadata) {
        return sharpImage
                .extract({
                  left: Math.round(metadata.width * parasedBody.x),
                  top: Math.round(metadata.height * parasedBody.y),
                  width: Math.round(metadata.width * parasedBody.width),
                  height: Math.round(metadata.height * parasedBody.height)})
                .toBuffer((err, outputBuffer, info) => {
                  console.log("BUFF FUNC ERR", err);
                  console.log("BUFF FUNC outputBuffer", outputBuffer);
                  console.log("BUFF FUNC info", info);
                })
        })

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

8reactions
lovellcommented, May 10, 2021

v0.28.2 is now available.

1reaction
lovellcommented, Apr 17, 2021

Commit https://github.com/lovell/sharp/commit/4237f5520f6dfcae2706e6d7ffe3cc3d3e05a604 adds a new output density property to withMetadata() to set the DPI resolution, which keeps things consistent with the input density property of metadata().

// Available from v0.28.2

const data = await sharp(input)
  .withMetadata({ density: 96 })
  .toBuffer();

This will be in v0.28.2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I specify the output sizes of JPEG, PNG, and TIFF ...
The JPEG, PNG, and TIFF drivers in MATLAB 5.x and later rely upon a figure's "PaperPosition" to specify the size of the output...
Read more >
Save or Export an Image as JPEG, PNG, GIF, etc - YouTube
Chris Recommends ◥Protect Your Online Privacy with NordVPN ▻▻https://go.nordvpn.net/SH4A0Save Money Shopping Online with Honey Extension ...
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