Skip to content

Chaining operations without losing quality #2453

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

Closed
igorescobar opened this issue Nov 23, 2020 · 2 comments
Closed

Chaining operations without losing quality #2453

igorescobar opened this issue Nov 23, 2020 · 2 comments
Labels

Comments

@igorescobar
Copy link

igorescobar commented Nov 23, 2020

Hi 👋 ,

Sometimes you need to do operations on images that you need to do a .toBuffer() so the next step of the image manipulation would use the output & metadata of the previous step.
The problem is that every time you do a sharp(image) the image seems to lose quality incrementally. Like

image = sharp(buffer).trim().toBuffer()
// ... some logic ...
image = sharp(image).resize().toBuffer()
// ... some logic ...
image = sharp(image).extract().toBuffer()

The code above is just an example but you can imagine that each operation might be on different files and image is like a shared context.

Is there any way you would recommend/suggest to do this without losing quality every time we sharp() the image buffer?

I read this discussion earlier: #241 and it seems that it might solve this specific problem but it seems that it's only a "concept" for now.

Let me know if I need to provide more info!

Thanks! 🙏

@lovell
Copy link
Owner

lovell commented Nov 24, 2020

Try a lossless format such as PNG, or (faster, higher memory usage) use raw pixel data.

@lovell
Copy link
Owner

lovell commented Jan 6, 2021

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 Jan 6, 2021
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