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

Support for (pixel-level) transparency when composing images #21

Closed
sebnozzi opened this issue Jan 6, 2014 · 4 comments
Closed

Support for (pixel-level) transparency when composing images #21

sebnozzi opened this issue Jan 6, 2014 · 4 comments
Assignees

Comments

@sebnozzi
Copy link

sebnozzi commented Jan 6, 2014

Given this icon, which has a transparent background:
(it only seems white on top of github's white background)

icon

And this image:

picture

When I compose the icon over the image, I would expect to see this:

expected

But instead I see this:
(note, again, that the rectangle surrounding the icon is transparent; you are seeing through the resulting image into the page's background)

result_normal_1 0

This is the code I used:

val pic = Image(new File("picture.jpg"))
val icon = Image(new File("icon.png"))

def combineImages(composite: Composite, targetPath: String) = {
  val result = pic.composite(composite, icon)
  result.writer(Format.PNG).withCompression(9).write(new File(targetPath))
}

combineImages(new NormalComposite(1.0), "result_normal_1.0.png")

It seems that the pixels from the incoming (second / icon) image are being taken "absolutely", replacing the pixels on the target (first / picture) image.

Each pixel should be combined not only taking into account the alpha parameter given to the composite object, but the transparency of each individual pixel.

For a reference implementation, compare with gimp (which was used to generate the "expected" result)

@sksamuel
Copy link
Owner

sksamuel commented Jan 6, 2014

This is in master now. You need to use the AlphaComposite, so

val background = ...
val icon = ...
val composed = background.composite(AlphaComposite(0.5f), icon)

Or whatever alpha you like. See AlphaCompositeTest for details.

@ghost ghost assigned sksamuel Jan 6, 2014
@sksamuel
Copy link
Owner

sksamuel commented Jan 6, 2014

image1

image2

@sebnozzi
Copy link
Author

sebnozzi commented Jan 7, 2014

Works fine!

I am of the opinion that this should be the behaviour for the NormalComposite. But I'll respect your design decisions and close this issue, since the functionality is there after all. Thanks!

@sksamuel
Copy link
Owner

sksamuel commented Jan 7, 2014

Yeah I guess that's better. I'll support it in Normal as well.

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

2 participants