-
-
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
Feature request: overlay images with transparency (was: Resize, combine multiple images) #97
Comments
Hi Kyle, would you be more interested in:
The underlying libvips library can handle both; neither are currently exposed via this module. |
@kembs ? |
Closing due to inactivity but please do feel free to reopen if this is still something you're looking for. |
@lovell I would be interested in blending two images of the different dimensions, perhaps taking advantage of an alpha transparency channel in the top image. I saw that vips has im_insert operation which could place one image over another at specified position. However, number of bands should be equal for both images or one of them should have one band. This feature will let me fully switch to sharp and remove graphicsmagick fallback for this operation |
Hi @oaleynik, libvips provides an [ifthenelse](http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/libvips-Hi conversion.html#vips-ifthenelse) operator that could be used for this - the transparency layer could be extracted and used as the The API might look something like: var image1 = sharp('image1.jpg');
var image2 = sharp('image2.png');
image1
.overlayWith(image2, top, left)
.toBuffer(function(err, data) {
...
}); In this example Does this make sense? (I'm planning to migrate to the new vips8 C++ API in 7.42.0+ later this year. This feature will be much easier to implement after doing so.) |
@lovell looks awesome! Exactly what I need and I think it will be useful for others. |
If I understand correctly, this would make watermarking images a breeze, and fits my use case perfectly |
+1 😄 |
FYI, I started exploring this and will try to report back on my progress later this week. |
Great news, thanks @gasi! |
@gasi Looking forward to it. Thanks! |
@lovell: I have a proof-of concept and while it’s rough, I’d appreciate your feedback: https://github.com/gasi/sharp/blob/89e6dfbd3ce0fe776b85a768d0e9c809693a0af6/test/unit/composite.c As stated in the PR (gasi#2), I have a feeling there must be a more concise and potentially more performant approach using |
Got it working using |
I started exploring how to integrate having two images being composited into the C++ extension. My guideline is your code snippet from above: var image1 = sharp('image1.jpg');
var image2 = sharp('image2.png');
image1
.overlayWith(image2, top, left)
.toBuffer(function(err, data) {
...
}); @lovell: Would you like this to be part of the |
Thanks for your great start on this feature Daniel. I'm also unsure if the use of It's worth noting all these techniques assume linear RGB. JPEGs without a profile are usually in a non-linear sRGB space so gamma correction may be required. Don't worry about this for now - a possible future enhancement. The We'll need to I suspect the most common use of this feature will be for watermarks. This would suggest a good place to apply this operation is just before the final conversion to sRGB. As for the JS API, we could start out more simply by supporting an experimental |
This is an experimental API and requires both images to have the same dimensions. TODO - Add support for overlaying different size image. - Add support for specifying position of overlay image, e.g. for watermarking. See lovell#97.
First of all, thanks for all the helpful comments, @lovell. I have an end-to-end proof of concept of
👍
Excited for this! Indeed, I can’t wait to get rid of all these
Agreed,
As stated above, we currently don’t have the use case of embedding smaller images but if it’s easy enough, one of us could add it later on.
Thanks for the tip! This is what I have done in my proof of concept.
👍 I simply implemented I am calling it a night 🌃 now but since you are in London with the day ahead of you, I thought I’d share my latest status. Please add your comments / thoughts to my pull request and I will try to address them tomorrow: gasi#2 😄 P.S. I have been playing around with ImageMagick’s |
As an amateur photographer, I have always heard about gamma but didn’t understand its meaning until I watched this video recommended by our intern Tony: https://www.youtube.com/watch?v=LKnqECcg6Gw&feature=youtu.be |
Thank you @gasi, I've commented inline on your latest additions. I've created the Containing this feature in a separate .c file makes a lot of sense right now as I will need to refactor/split ResizeWorker ahead of #152. This means your code will move into something like an Task #122 covers adding the use of perceptual (i.e. frequency-based) image hashing to test assertions - feel free to add ideas and comments there. |
This is an experimental API and requires both images to have the same dimensions. TODO - Add support for overlaying different size image. - Add support for specifying position of overlay image, e.g. for watermarking. See lovell#97.
Thanks, @lovell. I rebased my work against I added some comments explaining my work and/or asking some questions. I’d appreciate if you could take a look and I will make sure to address your feedback 👍
👍
Good idea. For now, I went with a simple approach using |
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.
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 #97.
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 #97.
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 #97.
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 #97.
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 #97.
Update: building on @gasi's great work on this feature, commit 1091be3 on the It currently still requires that the two images have the same dimensions. For watermarking, I think all that remains is the ability to apply a gravity to the overlay image so its dimensions can differ from the underlying image. |
Need to test PNGs with bit depths other than 8 - see #237 |
This feature is now in territory. #239 created to track support of differing dimensions. |
@lovell wonderful! Can't wait for it! |
Now in master awaiting release. |
What about combining more than 2 images (all of the same dimensions)? |
@MPSinclair You'll need to make two passes to do this. Raw pixel input/output is supported so this will remain fast, albeit at the cost of having the whole uncompressed image in memory. Happy to provide more details in a new question/issue if required. |
Hello,
I was wondering if I could get help if this is possible with this library. I've been looking at the documentation and the code but can't find any info for combining multiple images on top of each other.
I assume I'd to do something like resize them beforehand and save them to buffers, then actually joining them?
Thanks
The text was updated successfully, but these errors were encountered: