faker icon indicating copy to clipboard operation
faker copied to clipboard

Ability to generate dark and light hex colors with a new optional luminosity option

Open nickjj opened this issue 3 years ago • 6 comments

Currently we can run Faker::Color.hex_color to generate a random hex color. It does not support any arguments.

It would be great if we could optionally run:

  • Faker::Color.hex_color(luminosity: 'dark')
  • Faker::Color.hex_color(luminosity: 'light')

To simplify the interface this option could default to random. There's other potential values that could be interesting too like bright or pastel but let's not get too crazy from day 1.

If this option existed it would be very easy to generate very nice looking random user avatars. It's common nowadays to generate a random color that is a circle and use the user's first name's initial in place of a photo by default. Darker colors tend to look much better here for that circle and this new feature would let us generate dark colors as needed.

The Python version of Faker has this behavior at https://faker.readthedocs.io/en/master/providers/faker.providers.color.html. I used the word luminosity based on their documentation as it's pretty much the perfect word to describe what this is.

Currently there's no workaround other than to not use this gem's hex_color generator and instead generate a custom color manually.

nickjj avatar Feb 20 '22 20:02 nickjj

I can tackle this feature! :)

adisonlampert avatar Mar 08 '22 19:03 adisonlampert

hi @adisonlampert how is your work going on the issue? Thanks!

stefannibrasil avatar Aug 28 '22 01:08 stefannibrasil

that would be a nice addition. +1 for this!

thdaraujo avatar Sep 12 '22 18:09 thdaraujo

Came here after seeing your youtube video @thdaraujo and @stefannibrasil 🚀

fbuys avatar Sep 20 '22 13:09 fbuys

Came here after seeing your youtube video @thdaraujo and @stefannibrasil 🚀

hooray! welcome, @fbuys !

thdaraujo avatar Sep 20 '22 16:09 thdaraujo

Welcome @fbuys it's great to see that the live session inspired you to start contributing to Faker :)

stefannibrasil avatar Sep 23 '22 03:09 stefannibrasil