Skip to content
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

How can I insert an image into an image, but keep the background transparent? #500

Open
konnorov opened this issue Mar 19, 2020 · 4 comments

Comments

@konnorov
Copy link

plz help(((

@iandoesallthethings
Copy link

I'm having the same problem. Image.insert() doesn't respect alpha values. Is there anything to be done about that?

@incanus
Copy link
Contributor

incanus commented Mar 28, 2022

One method is to iterate pixels with getPixelXY() for both source and destination images and apply the Porter-Duff algorithm as described here under The mathematics of alpha compositing:

https://apoorvaj.io/alpha-compositing-opengl-blending-and-premultiplied-alpha/

It's quite easy to do and has worked well in a project of mine.

Though this project could benefit from a composite() operation, or else improvements to insert().

@targos
Copy link
Member

targos commented Mar 28, 2022

I'm sorry if we are not very responsive on this issue tracker, but we are currently working hard on a TypeScript rewrite of the library in https://github.com/image-js/image-js-typescript
It contains a new copyTo method which I think does what this ticket is asking for.

@moruzerinho6
Copy link

Any timeline for the rewrite? Having the same problem and as OP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants