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

Overwrite opaque pixels with transparent ones when compositing #4290

Open
VendoAU opened this issue Dec 7, 2024 · 2 comments
Open

Overwrite opaque pixels with transparent ones when compositing #4290

VendoAU opened this issue Dec 7, 2024 · 2 comments
Labels

Comments

@VendoAU
Copy link

VendoAU commented Dec 7, 2024

Question about an existing feature

What are you trying to achieve?

I want to place an image with transparency on top of another, but cut through the original image so it is still fully transparent.
I looked through the blend modes and I couldn't figure out how to do this without creating another image to use as a mask.

When you searched for similar issues, what did you find that might be related?

This was somewhat related, but I couldn't find any cutout method in the current version: #1016

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

const a = await sharp("A.png").toBuffer();
const b = await sharp("B.png").toBuffer();

const c = await sharp(b)
    .composite([{ input: a, left: 0, top: 0 }])
    .toFile("C.png");

Please provide sample image(s) that help explain this question

A:
A
B:
B
A and B combined (I want the center to be transparent like this):
C

@lovell
Copy link
Owner

lovell commented Dec 7, 2024

Did you see the dest-in blend? This can be used to "cut out" one image from another.

await sharp("B.png")
  .composite([{ input: "A.png", left: 0, top: 0, blend: "dest-in" }])
  .toFile("C.png");

@VendoAU
Copy link
Author

VendoAU commented Dec 8, 2024

Yes, but I don't think that will help
This is what the result is:
C

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

No branches or pull requests

2 participants