-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
sharp was working fine but doesn't anymore #4139
Comments
Please provide much more information about what you changed between "working" and "doesn't work". Please provide sample image(s). This appears to relate to #4076 |
I haven't changed a thing... I updated my code which uses sharp, the white background removal (#4076) didn't work any more, so I rollback it but unfortunately I have the impression that it still doesn't work whereas before with the changes you suggested it worked... Here is my code:
For example with this code, if I take this as entry: |
From the snippet of code provided here I can see a I also see use of a Perhaps you could provide a complete, standalone repo without any networking dependency that allows someone else to reproduce. |
My snippet wasn't entirely correct, sorry. Here is my updated current snippet:
For this code snippet, for these pictures input: I get this output composite image with still the white background on each sub images: As you said, this issue is related to #4076 |
It looks like the If you still require help, please provide a complete, standalone repo without any networking dependency that allows someone else to reproduce. |
here you go: |
Thank you, I've been able to reproduce locally. It looks like you upgraded from 0.33.3 (or earlier) to 0.33.4 and introduced #4096 which was supposed to make the What you can do is invert the logic here, threshold pixel values above 245 (max of 255 minus the original threshold of 10) then negate, which feels slightly more logically anyway: - const maskImage = await sharp(imageBuffer).negate().threshold(10).toBuffer();
+ const maskImage = await sharp(imageBuffer).threshold(245).negate().toBuffer(); |
Thanks for your reply. The change you suggested seems to work, I applied it but however, I seem to have another problem. I've updated the repository with new image links, and now the script doesn't seem to be working for these ones.
|
Okay I found the solution, I just had to convert the image to png:
|
Great, thanks for the update, glad you worked it all out. |
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
npm install sharp
completes without error.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?
sharp
as reported bynpm 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: macOS 14.5
CPU: (8) arm64 Apple M2
Memory: 54.34 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
npmPackages:
sharp: ^0.33.4 => 0.33.4
Does this problem relate to file caching?
The default behaviour of libvips is to cache input files, which can lead to
EBUSY
orEPERM
errors on Windows.Use
sharp.cache(false)
to switch this feature off.sharp.cache(false)
does not fix this problem.Does this problem relate to images appearing to have been rotated by 90 degrees?
Images that contain EXIF Orientation metadata are not auto-oriented. By default, EXIF metadata is removed.
To auto-orient pixel values use the parameter-less
rotate()
operation.To retain EXIF Orientation use
keepExif()
.Using
rotate()
orkeepExif()
does not fix this problem.What are the steps to reproduce?
This code was working fine, but doesn't work anymore:
Try to negate and threshold a image, it will not change the image:
What is the expected behaviour?
The expected behaviour is that the white image background is removed.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
Please provide sample image(s) that help explain this problem
The text was updated successfully, but these errors were encountered: