-
-
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
Incorrect behavior of overlayWith() #566
Comments
The Clip-to-fit would be my expected outcome here too, so I'll need to investigate why that's not occurring. Thanks for the report. EDIT: I'm completely wrong here, sorry, a 50px high image overlaid at |
It looks like there's a typo at common.cc#L394 - the following diff seems to fix it locally, so this is a confirmed bug. - } else if(x >= (inHeight - outHeight)) {
+ } else if(y >= (inHeight - outHeight)) { Thanks for the test case - I'll be adding something very similar to the functional tests to guard against any regression. |
Commit 28ce33f adds a test that would have caught this problem along with the fix. Thanks again for reporting this! |
Thank you! That was pretty quick. I'll try to test it out soon. I think you can close this issue. |
This fix is in v0.16.1, now available via npm. |
@lovell Thanks, and fix confirmed on my end. I tried literally a few hours ago to install via the GitHub repo, but failed (Some build requirement failed to download. Probably just the firewall here in China). Just tried it now via npm and it works perfectly. 🎉 |
The situation is that, under certain reproducible circumstances,
overlayWith()
overlays at the wrong location. This is best demonstrated with an example:This works, but because
top
is set to 49, there is a 1px gap at the bottom. Changingtop
to 50 causes it to move all the way to the top of the image (probablygravity
gets set tonorth
for some reason).I am guessing this is caused by an off-by-one-error (though that doesn't explain why it is overlayed at the top).
In any case, if the overlay cannot fit inside the image, it seems it should either throw an error, or it should simply clip so it fits (this would even allow negative coordinates). That is how JIMP works, and also the desired behavior in my case (I have improvised by dynamically cropping the overlay to only that area that should fit inside the image).
Of course, I can see why you may not want to do that, but I don't think suddenly jumping the image to the top is the intended behavior.
I'm attaching a minimal, complete, verifiable example so you can reproduce this yourself. Download, extract, and
npm install
. Then runnode index.js
and check the output inout.png
.The text was updated successfully, but these errors were encountered: