Open rugk opened 6 years ago
For obvious reasons it mostly happens, when you select two very light or two very dark colors.
I already implemented the first part. Apart from this, I think, this is now an easy issue and something I really would like to get some input on how to do it best.
As for implementation it mostly only happens in the Colors
module, so it is quite constrained.
This can even result in a loop… 🤔
Oh I found a bug. See https://github.com/rugk/offline-qr-code/commit/21c544a4be46e48e6560b7cd660b95c1c83c9da7. I used the inverted color on the wrong element. This mitigates this problem a bit. Just for visually appealing I would still suggest to still mix in some randomness.
For some reason, however, it does still show an info message (<4.5 contrast ratio) for these colors:
#78c272
#873d8d
And these are contrast colors – at least if you press the button it does not change anything. However, the contrast ratio is still only 3.16. So the contrast code does not seem to have a bug, but actually the code to invert colors is also simple – as we have implemented it here. Or is it actually correct that the inverted color does not have to have a high contrast? 🤔
The same e.g. works with the colors in the first example I gave in the originating post.
It seems to be reproducible when both colors seem to be from the "middle" here:
…i.e., when they are not very bright, but rather mixed with grey. Or maybe I am totally wrong here.
If you choose two grey colors and maybe even make them split nearly 50:50 between dark and white, they of course are also inverted colors, but have a really low contrast… 😐
Maybe https://www.utdallas.edu/~melacy/pages/2D_Design/Itten_ColorContrasts/IttenColorContrasts.html is a read, which could help. As the "inverted" color should actually be called "complementary" color…
STR
Set these options: Qr code color:
#9494E2
background color:#6B6B1D
What should happen: The "best color" should fulfill their own requirement and not yield an error/rwarning message.
Ideas for implementation
Or does someone can come up with some maths, for the "best color" here, so the algorithm does not have to guess in a loop?
/cc @ENT8R, @LMLB
(follow-up of https://github.com/rugk/offline-qr-code/issues/19)
Edit: The new algo should not override the "getContrastColor", i.e. that should still be exposed. We may then not use it, but I consider it is a nice thing for such a module.