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

Define a common 'opacity' value for each color instance #75

Closed
jcogs-design opened this issue May 14, 2022 · 1 comment
Closed

Define a common 'opacity' value for each color instance #75

jcogs-design opened this issue May 14, 2022 · 1 comment

Comments

@jcogs-design
Copy link
Contributor

While this might be fixed by transitioning to use of a common / universal color definition for internal storage (i.e. all colours are instances of a generalised colour definition, converted on demand to whatever format is requested), until then I think there is a case for defining an additional property for colour classes which evaluates to 0->1 opacity.

Consider this example - imagine you do the following:

$the_colour = @Factory::fromString('#22334455');
echo $the_colour->alpha(); // 55;

If you then want to convert this to RGBA you might do

echo $the_colour->rbga($the_color->alpha()); // error - due to alpha (55) value being out of required range (0->1)

So to make this conversion the developer using library needs to first check what format the colour being converted is and adjust the alpha value to one that will be accepted by the RGBA method. This is unnecessary, and by making it happen outside of the library increases liklihood of errors being introduced.

A better solution might be to calculate an "opacity" value for each colour definition - translating whatever opacity format information is held in the colour format into a value in range 0->1 - so in this case the hex 55 value would translate into 0.33 opacity value.

Then developers could use the following form without worry:

echo $the_colour->rbga($the_color->opacity()); // rgba(34,51,68,0.33)

Does this sound like it is worth doing? Or is work on a unified colour model a better thing to spend time on?

@spatie-bot
Copy link

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

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