-
-
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
Fix erroneous top/left clipping in composite #2571 #2594
Conversation
Fixes bug where certain input values for top/left parameters in composite can conflict with clipping logic, resulting in inaccurate alignment in output png. Adds logic to run check which determines if clipping needs to be applied. Issue #2571
Thank you for the PR. If you're able to add a unit test to test/unit/composite.js with an example scenario this change fixes, that would be amazing. |
Hi, sure! I'm not familiar with unit tests yet, so I'll do some reading on it and get back to you when I've taken a crack at it. |
Hi, I'm not entirely sure how to tackle this unit test, if you have a moment could you clarify the process for me? I've reviewed the unit test file you linked, and I've done some reading on Javascript unit testing as a concept, but I'm not sure how to apply that to this specific issue, since I only discovered the bug due to a very particular set of circumstances in my project. How would I write a test that demonstrates this fix? |
Here's a possible test case that checks colour of the top-left pixel after compositing a 2x2 blue over a 2x2 red image at an offset of 1+1. The current version of sharp will incorrectly clip the offset and produce a top left pixel that is blue, but with the change in this PR it should be corrected to red (as only the bottom right pixel should be blue). it('Allow offset beyond bottom/right edge', async () => {
const red = { r: 255, g: 0, b: 0 };
const blue = { r: 0, g: 0, b: 255 };
const [r, g, b] = await sharp({ create: { width: 2, height: 2, channels: 4, background: red } })
.composite([{
input: { create: { width: 2, height: 2, channels: 4, background: blue } },
top: 1,
left: 1
}])
.raw()
.toBuffer();
assert.strictEqual(red, { r, g, b });
}); If this works, please feel free to add it as a test case to |
Hi, I keep getting a test failure on that. Just to make sure, should I be adding it at a specific line in
|
Sorry, try I'm slowly moving tests to using async/await where it makes sense to do so as I find it usually simplifies the flow, makes the intent clearer and offloads more error handling onto the test runner. |
Thanks, that worked! Gonna go ahead and add it to the test file. |
Unit test to allow composite operations to have a top/left offset that causes the content to extend beyond the bottom/right edges of output. Pull Request #2594
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant, thank you for fixing this, I'll get this merged for v0.28.0.
Landed via commit 34a2e14 |
#2571 Fixes bug where certain input values for top/left parameters
in composite can conflict with clipping logic, resulting in
inaccurate alignment in output png. Adds logic to run check
which determines if clipping needs to be applied.
Issue #2571