-
-
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
Enhancement: ensure metadata.background is compatible with color package for single-channel images #4090
Comments
The simplest solution here is probably to always return an RGB Object in Happy to accept a PR for this, if you're able. We should add a test case for this too as it doesn't appear to be covered by any of the scenarios in test/unit/metadata.js at the moment. |
Removing greyscale number return type from Adding additional parameter type for |
I'm OK with this being a breaking change, as part of a future possible v0.34.0, as it simplifies the API so that the Perhaps a single-channel input could return something like |
When using
sharp(input).metadata()
an object with properties, which includesbackground
is returned.It can return RGB Object or greyscale number.
When using
sharp(input).flatten()
we can pass in an options object which includes the background color property. This option expects an RGB Object or a CSS type color string (e.g. 'white').What I did, was use the background color returned by
.metadata()
, directly as an option in.flatten()
. This however, produced an error in cases where the metadata returned a greyscale number, which is not a valid input for flatten background option.Current workaround is simple: just repeat the greyscale number value for all the RGB Object fields.
However, while the "fix" is simple, it is not the expected behavior and should be adjusted. I propose that the
.flatten()
background
option accepts a greyscale number as possible input.The text was updated successfully, but these errors were encountered: