-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Feature request
What are you trying to achieve?
I have a bulk of small images which I .trim() to zoom into the actual content.
Later on, I run some analysis on the image which performs better with padding/margin.
Instead of trimming all the way to the content, I'd like to keep a small padding/margin around it.
When you searched for similar feature requests, what did you find that might be related?
What would you expect the API to look like?
await sharp(input)
.trim({
threshold: 0,
marginPx: 10 // 10px margin around the image when trimming
})
.toFile(output);What alternatives have you considered?
I'm aware of the .extend() that may help achieve the same thing but it defaults to black as a background colour. I'd like to preserve the original shade.
I suppose, I could also pull the top-left pixel colour, trim and then apply extend with the same colour. However, that may lose potential gradient backgrounds that still fall into the trimming threshold.
In addition, I'm willing to contribute the feature.
Please provide sample image(s) that help explain this feature
Before
After with margin/padding
danil-baranovskyi