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

v0.31 trim() failing with an unclear error message #3636

Closed
mquandalle opened this issue Apr 19, 2023 · 4 comments
Closed

v0.31 trim() failing with an unclear error message #3636

mquandalle opened this issue Apr 19, 2023 · 4 comments

Comments

@mquandalle
Copy link

mquandalle commented Apr 19, 2023

Updating sharp from v0.30.7 to v0.31.0, I'm getting an error with the following code:

const img = sharp(imgPath).trim();
await img.toFile(newImgPath)

The error message is a bit cryptic:

[Error: linear: vector must have 1 or 4 elements]

Image:

logo_ville_villeneuve_les_avignon

The error is still present in v0.32

@lovell lovell added bug and removed triage labels Apr 20, 2023
@lovell
Copy link
Owner

lovell commented Apr 20, 2023

Hi, thanks for reporting, this image is CMYK and it looks like the trim() operation is erroneously dropping the K channel internally when determining the background colour, hence the rather cryptic error message. This code could probably do with a bit of a refactor anyway so leave it with me.

@lovell lovell added this to the v0.32.1 milestone Apr 20, 2023
@lovell
Copy link
Owner

lovell commented Apr 20, 2023

Commit 8408e99 makes the background colour logic more generic, which fixes this problem. There's also a new test that would previously have failed.

@mquandalle
Copy link
Author

Thank you so much for the super quick response and fix!

@lovell
Copy link
Owner

lovell commented Apr 27, 2023

v0.32.1 now available.

@lovell lovell closed this as completed Apr 27, 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