-
-
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
Add support for clipping/cutting out (#435) #448
Conversation
using sharp::MaximumImageAlpha; | ||
|
||
bool maskHasAlpha = HasAlpha(mask); | ||
bool dstHasAlpha = HasAlpha(dst); |
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.
I think dstHasAlpha
will always be true
as there's logic elsewhere to ensure the presence of an alpha channel.
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.
Fantastic, thank you for this Kleis. It's always a pleasure to see tests and I'm happy to update the docs etc. I've added a few comments inline. |
USAGE: overlayWith('overlayimage.png', { cutout: true } )
Updates look great, thank you.
I think the best approach is to avoid premultiplying the image to be overlaid, assuming there are no other reasons for This will avoid (a) a performance hit, (b) a source of rounding/clipping errors, and (c) potential light/dark artefacts at the "edges" of what was the discarded alpha channel. |
A general Porter-Duff compose operator could solve this problem too. vips will need PD at some point. |
@kleisauke Would you like to remove the premultiply logic here or would you prefer I take a look? |
@lovell I already did that. See: pipeline.cc#L463-L464 and pipeline.cc#L698-L700. |
@kleisauke You are absolutely correct - sorry I completely missed that. Thank you again for adding this very useful feature! |
@lovell No problem! Thanks for merging the pull request! 👍 |
Usage:
overlayWith('overlayimage.png', { cutout: true } )
Only the API Docs and changelog needs to be updated. Test cases are included.
Thanks to @jcupitt for the help provided here.