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 :-/
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.
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
Carlo
–
Se la Strada e la sua Virtu' non fossero state messe da parte,
K * Carlo E. Prelz - removed[email protected] che bisogno ci sarebbe
di parlare tanto di amore e di rettitudine? (Chuang-Tzu)