-
-
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
API: sharp.overlayWith
(alpha compositing)
#207
Conversation
@@ -30,6 +30,8 @@ Please select the `master` branch as the destination for your Pull Request so yo | |||
|
|||
Please squash your changes into a single commit using a command like `git rebase -i upstream/master`. | |||
|
|||
To test C++ changes, you can compile the module using `npm run compile`. |
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.
This was useful to me and hope it will be to others 😄
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.
This will compile but not test the changes. I usually use npm i
to do both.
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.
Oh, you’re right, I didn’t know npm install
runs node-gyp
on the package itself. I always tried npm rebuild
but that only recompiles dependencies. However, you said it ‘will […] test the changes’. This doesn’t happen for me (see below). Am I missing something?
npm i
> [email protected] install /Users/dani/workspace/sharp
> node-gyp rebuild
CXX(target) Release/obj.target/sharp/src/common.o
CC(target) Release/obj.target/sharp/src/composite.o
CXX(target) Release/obj.target/sharp/src/utilities.o
CXX(target) Release/obj.target/sharp/src/metadata.o
CXX(target) Release/obj.target/sharp/src/resize.o
CXX(target) Release/obj.target/sharp/src/sharp.o
SOLINK_MODULE(target) Release/sharp.node
SOLINK_MODULE(target) Release/sharp.node: Finished
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.
Sorry, my mistake. Judging by the command line history npm i && npm t
will do both.
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.
No worries, I documented npm install
and npm test
👍
Thanks again Daniel for all your work on this very useful and much-requested feature. I'm not sure I want to go down the route of using *magick for image comparisons. My experience of managing CI environments warns me otherwise (I'm looking at you, AppVeyor) and, more importantly, I believe libvips can do this with minimum effort. I'll spend some time this afternoon to see what I can do using libvips to get #122 off the ground. |
Commit c159948 on the By way of example, all of the tests for the extract method now employ it. |
Awesome! Thanks for providing this and I agree it’s more elegant without the GraphicsMagick dependency. However, I have two observations:
|
@@ -4,6 +4,7 @@ | |||
"maxparams": 4, | |||
"maxcomplexity": 13, | |||
"globals": { | |||
"before": true, |
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.
Although I don’t use this anymore, I figure it might be valuable for the future 😄
/* | ||
Composite images `src` and `dst`. | ||
*/ | ||
int Composite(VipsObject *context, VipsImage *src, VipsImage *dst, VipsImage **out); |
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.
Getting used to your 140 line length limit. I usually operate at 80 out of habit 😉
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.
People who use an 80 limit do so to leave room at the side of their monitor for Twitter.
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.
Haha, good one 😜 On a more serious note: I do it because I like to do three-way merges on my laptop 👍
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.
Then there is science 😉 http://baymard.com/blog/line-length-readability
@lovell I made another pass on this today and it should be ready to merge given the restrictions we talked about (only RGBA images can be composited). I might be able to add more functionality at some point but for now, I think this might be already valuable for some people 😄 |
vips_object_local(context, joined); | ||
|
||
// Return a reference to the output image: | ||
g_object_ref(joined); |
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 this g_object_ref
can be removed as vips_object_local
will reference joined
.
Thanks again for all your work on this Daniel. Other than the possible reference leak, this is definitely ready to merge into the |
sharp.overlaysWith
(alpha compositing)sharp.overlayWith
(alpha compositing)
Composites an overlay image with alpha channel into the input image (which must have alpha channel) using ‘over’ alpha compositing blend mode. This API requires both images to have the same dimensions. References: - http://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending - libvips/ruby-vips#28 (comment) See lovell#97.
Thanks, I simplified the |
I forgot to add |
Initial version of overlayWith method for alpha compositing
No worries on the docs. I intend to add the ability to overlay onto non-alpha images too and will update the README after that. Thanks again @gasi for all your work on this new feature! |
Thanks, @lovell, I appreciate it 👍 |
Adds
sharp.overlaysWith
for compositing an image on top of another image while handling alpha channels correctly.I left all commits intact for better understanding but feel free to merge as one squash commit, @lovell.
This is now ready for review.
Tests and usage examples:
test/unit/overlay.js
TODO
Test with non-PNGs.Non-4-channel images are not supported.Add support for specifyingPunted.top
andleft
position as insharp.overlaysWith(filename, top, left)
. This might be useful for watermarking.convert -composite
output. Not visible to human eye (at least not mine 😉) but detectable bycompare …
.References
See: #97.