Change fond color based on dark/light bg

Dear Sirs,

I have a little application that displays weather info for a digital
signage system. As of today displays just letters and numbers on a solid
color background. I would like to make it
prettier, thus I managed to grab the background and weather image from
“Yahoo! weather” and display it.

The problem that the background changes in colors. It’s bright colored
by day and dark colored by night, so I need to find a way to change
font-colors based on the background. I’m using HAML, CSS and Sinatra.

Can you think of any way of doing something like that? Apparently I
can’t do that using CSS or SASS (not 100% sure though).

Is there any way I can have ruby read the BG color and then decide if
I’ll display the ‘weather_light’ route or the ‘weather_dark’ sinatra
route?

Other ideas would be pretty much welcomed as I found my self completely
our of ideas on how to proceed :-/

Best Regards,

Panagiotis (atmosx) Atmatzidis

email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0xE736C6A0
gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xE736C6A0

Subject: Change fond color based on dark/light bg [Sinatra,HAML,CSS]
Date: sab 06 apr 13 02:54:01 +0900

Quoting Panagiotis A. ([email protected]):

sinatra route?
You can extract the average luminosity from an image - just decompres
it, then sum all the bytes and divide by the number of bytes - you’ll
have a number between 0 and 255. Lower than 128 -> weather_dark,
else weather_light.

Of course you should get a copy of the image yourself, in order to
process it. It is not clear from your mail if you serve these
backgrounds yourself or you redirect elsewhere. If you redirect, you
can always have a background task that runs maybe once per hour, gets
retrieves a copy of the image and sets a variable that is accessible
within Sinatra (possibly a global variable) with the current
luminosity.

Carlo

Hello,

On 5 Απρ 2013, at 20:39 , Carlo E. Prelz [email protected] wrote:

Can you think of any way of doing something like that? Apparently I
can’t do that using CSS or SASS (not 100% sure though).

Is there any way I can have ruby read the BG color and then decide
if I’ll display the ‘weather_light’ route or the ‘weather_dark’
sinatra route?

You can extract the average luminosity from an image - just decompres
it, then sum all the bytes and divide by the number of bytes - you’ll
have a number between 0 and 255. Lower than 128 -> weather_dark,
else weather_light.

Thanks, that’s a great idea. I’ll give it a shot.

Of course you should get a copy of the image yourself, in order to
process it. It is not clear from your mail if you serve these
backgrounds yourself or you redirect elsewhere. If you redirect, you
can always have a background task that runs maybe once per hour, gets
retrieves a copy of the image and sets a variable that is accessible
within Sinatra (possibly a global variable) with the current
luminosity.

I can easily download and process locally both images, it’s not a
problem :slight_smile:

Carlo

  •     Se la Strada e la sua Virtu' non fossero state messe da parte,
    
  • K * Carlo E. Prelz - [email protected] che bisogno ci sarebbe
  •           di parlare tanto di amore e di rettitudine? (Chuang-Tzu)
    

Panagiotis (atmosx) Atmatzidis

email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0xE736C6A0
gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xE736C6A0