Skip to content

Gray::toRgb rounding error #184

@AntonioDiPassio-AppSys

Description

@AntonioDiPassio-AppSys

line 34:
return new Rgb((int) ($this->gray * 2.55), (int) ($this->gray * 2.55), (int) ($this->gray * 2.55));

If $this->gray is 100, it will return Rgb(254,254,254)

because PHP being weird and: (int) (100 * 2.55) = 254

Can be fixed by changing it to:
return new Rgb((int) ($this->gray * 255 / 100), (int) ($this->gray * 255 / 100), (int) ($this->gray * 255 / 100));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions