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

blur -> threshold chaining doesn't work as expected #3697

Closed
1 task done
thot-experiment opened this issue Jun 13, 2023 · 4 comments
Closed
1 task done

blur -> threshold chaining doesn't work as expected #3697

thot-experiment opened this issue Jun 13, 2023 · 4 comments
Labels

Comments

@thot-experiment
Copy link

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

What are the steps to reproduce?

When chaining .blur().threshold() the threshold step is not perfomed

What is the expected behaviour?

.threshold() should be performed

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

import sharp from 'sharp'
import fs from 'fs/promises'

let file = await fs.readFile('test.png')

let onepass = await sharp(file)
.blur(10)
.threshold()
.toBuffer()

//as a temporary workaround one can do a second pass rather than chaining operations
let twopass = await sharp(onepass)
.threshold()
.toBuffer()

fs.writeFile('blurry_but_not_thresholded.png', onepass)
fs.writeFile('blurry_and_thresholded.png', twopass)

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

test.png

test

blurry_but_not_thresholded.png

blurry_but_not_thresholded

blurry_and_thresholded.png

blurry_and_thresholded

@lovell
Copy link
Owner

lovell commented Jun 13, 2023

Hi, your approach to split this task into two passes is correct. (My understanding is that threshold then blur is more generally useful, or at least this was the case when this feature was added in 2015.)

@thot-experiment
Copy link
Author

thot-experiment commented Jun 13, 2023

Thanks for the reply. Is there guidance on how this is supposed to work? Intuitively it seems like I should be able to chain things in whatever order I want but this isn't the case? There's some internal order of precedence? Perhaps there's something I missed in the docs? I'm definitely intending to use the operations in the order listed here.

@lovell
Copy link
Owner

lovell commented Jun 13, 2023

Please see #241 for discussion about future possible API improvements.

@lovell
Copy link
Owner

lovell commented Jun 23, 2023

I hope this information helped. Please feel free to re-open with more details if further assistance is required.

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

No branches or pull requests

2 participants