From: "Carlo E. Prelz" Date: 2013-04-06T03:39:50+09:00 Subject: Re: Change fond color based on dark/light bg [Sinatra,HAML,CSS] Subject: Change fond color based on dark/light bg [Sinatra,HAML,CSS] Date: sab 06 apr 13 02:54:01 +0900 Quoting Panagiotis Atmatzidis (atma@convalesco.org): > 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? 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 -- * Se la Strada e la sua Virtu' non fossero state messe da parte, * K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)