Skip to content

Transparent pixels with different RGB values fail on assertSimilarGD #16

@bennothommo

Description

@bennothommo

An issue I've seen crop up from time to time when using this library is when transparent pixels between two images (ie. alpha = 127) have differing RGB values. When viewing the images, they are exactly the same, for example:

transparent-black
transparent-white

Both two images look exactly the same, but the top one has a transparent black background around the edge (RGB 0) and the bottom one has a transparent white background around the edge (RGB 255). Due to the RGB values being different, all these edge pixels are considered different, and thus the threshold of the test has to set to a threshold high enough to cover the percentage of the image that these pixels take up.

I have experimented applying a different colour difference calculation that takes the alpha channel into account when calculating the difference of the RGB channels and basically use a percentage of the RGB values depending on the opacity - for example, at 50% opacity, the RGB values are halved and thus the delta of difference is less, and at 0% opacity, the RGB values are considered to be 0 themselves, meaning not taken into account at all for difference. This started to go into the realm of determining differences based on opacity which might be outside of the scope for this library.

I'm interested to hear your thoughts on whether you would be amenable to a PR that includes such calculations, or if for now, a smaller scoped PR that just ignores RGB values when the pixel is transparent?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions