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

Execution freezes when calling rotate + extract + resize with transparency in background #3722

Closed
3 tasks done
pedro-pedrosa opened this issue Jul 6, 2023 · 4 comments
Closed
3 tasks done

Comments

@pedro-pedrosa
Copy link

pedro-pedrosa commented Jul 6, 2023

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

  System:
    OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i7-4700HQ CPU @ 2.40GHz
    Memory: 2.40 GB / 15.50 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.21.1 - /usr/bin/yarn
    npm: 8.5.5 - ~/.nvm/versions/node/v16.15.0/bin/npm
    Watchman: 4.9.0 - /home/linuxbrew/.linuxbrew/bin/watchman
  npmPackages:
    sharp: ^0.32.1 => 0.32.1 

What are the steps to reproduce?

Download the sample image then run the example script on it

What is the expected behaviour?

I should get an output, but the toBuffer promise never resolves. If I change the height of the extract transform to 1439 or lower, it works. If I change the resize params to 1920x1080, it works. If I change the bg color param of the rotate transformation to { r: 0, g: 0, b: 0, alpha: 1 }, it works.

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

var sharp = require('sharp')
var fs = require('fs')
var input = fs.readFileSync('./o.jpeg')
var result = sharp(input)
result = result.rotate(28, { background: { r: 0, g: 0, b: 0, alpha: 0 } })
result = result.extract({ left: 341, top: 1093, width: 3521, height: 2279 })
result = result.resize({ width: 640, height: 360, fit: 'outside', background: { r: 0, g: 0, b: 0, alpha: 0 }})
result = result.jpeg()
result.toBuffer().then(o => {
  fs.writeFileSync('./o2.jpeg', o)
})

Please provide sample image(s) that help explain this problem

o

@lovell
Copy link
Owner

lovell commented Jul 7, 2023

Thanks for reporting, I can reproduce this.

I've created a smaller test case to remove any format (de)coding and keeping everything RGB-only, which produces the same problem.

sharp({
  create: { width: 4640, height: 2610, channels: 3, background: "black" },
})
  .rotate(28)
  .resize({ width: 640, height: 360 })
  .raw()
  .toBuffer();

This looks a bit like a deadlock in the affine operation - I'll keep investigating.

@lovell lovell added this to the v0.32.2 milestone Jul 9, 2023
@lovell
Copy link
Owner

lovell commented Jul 9, 2023

This is due to over-computation in the affine operation - it will complete eventually.

Commit 14c3346 fixes this by caching the intermediate output and adds a test case that would previously have timed-out and therefore failed. This will be in v0.32.2.

@pedro-pedrosa
Copy link
Author

that's great. thank you for looking into it so promptly

@lovell
Copy link
Owner

lovell commented Jul 11, 2023

v0.32.2 now available.

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

No branches or pull requests

2 participants