-
-
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
Black outlines in image are removed when using trim() #2265
Comments
The black outline in this image is part of the alpha channel - please see #2166 for a future possible enhancement to address this. |
Is there another manipulation I can do prior to trimming to work around this issue? To somehow move the outline out of the alpha channel? |
I have found that if I I was then able to using the offsets mentioned in the docs, to crop (
const flattened = await sharp(inputFilePath)
.flatten({ background: { r: 255, g: 0, b: 255 } })
.removeAlpha()
.toBuffer();
sharp(flattened)
.trim()
.toBuffer((err, data, info) => {
const crop = {
left: -info.trimOffsetLeft,
top: -info.trimOffsetTop,
width: info.width,
height: info.height,
};
return sharp(inputFilePath)
.extract(crop)
.toFile(outputFilePath)
}); This is probably a sluggish work around, but it appears to work well enough for my use case. |
Closing in favor of #2166 |
version:
[email protected]
What are the steps to reproduce?
Attempt to trim the attached example file.
Input
Output
What is the expected behaviour?
Black outlines would be preserved.
What is the output of running
npx envinfo --binaries --system
?The text was updated successfully, but these errors were encountered: