From: Panagiotis Atmatzidis Date: 2013-04-06T03:44:31+09:00 Subject: Re: Change fond color based on dark/light bg [Sinatra,HAML,CSS] Hello, On 5 Απρ 2013, at 20:39 , Carlo E. Prelz wrote: > 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. 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 - fluido@fluido.as che bisogno ci sarebbe > * di parlare tanto di amore e di rettitudine? (Chuang-Tzu) > Panagiotis (atmosx) Atmatzidis email: atma@convalesco.org URL: http://www.convalesco.org GnuPG ID: 0xE736C6A0 gpg --keyserver x-hkp://pgp.mit.edu --recv-keys 0xE736C6A0 -- The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience."