View Full Version : converting "scrollbar" color to hexadecimal format
james438
10-10-2009, 07:30 PM
colors come in different formats like color:#000000; color:red; color:#056; 0x00, 0x00, 0x00
Is there a way to use php to convert the format of converting one of the formats listed above into another? I think I could design something that will convert the first format to the last one, but I am most interested in converting something like color:scrollbar; to color#000000;
I figure if I could use php to create a jpg of color scrollbar I could use imagecolorat() or imagecolorclosest() to convert it to a hex format.
djr33
10-10-2009, 08:41 PM
First question: yes, you can convert between the different kinds of colors. You would need a list of the named colors ("red") corresponding to a numerical value for them. The others just need some fairly basic math. You should be able to find information on this through google. Remember that they all represent colors in terms of red value, green value, and blue value: combined they give you a color. So each method is different, but entirely convertible. However, there is no default color conversion function in php, so you will have to do it yourself. There are tools for dealing with hexidecimal values, though, so that will save some time. I've written a couple conversions here or there (nothing I can find/extract for you, because most of it is just very basic/need-based specific task conversion), and it's fairly simple.
I really don't understand what you're talking about with the scrollbar.
imagecolorat() is fine if you have an image, but why would a CSS property give you an image?
And you can't automatically do a print screen with php, etc. PHP is only serverside. There is no way I know of to force a screen capture, etc, but certainly not with php. (MAYBE with a Java applet, probably not flash.)
Plus, what is "color:scrollbar"? Do you mean you're referring to a certain kind of property, so it's defined somewhere else? Then just get it from the original source.
james438
10-11-2009, 12:36 AM
scrollbar is a color. There are so many named html color codes that some are rather obscure like "scrollbar". Scrollbar is a very light as I remember. I didn't want to say red or black, because I figured the temptation would be to answer the question by stating the hex code off the top of their head, which is easy enough. Then again "scrollbar" is obscure enough that I am more likely to confuse people than anything else.
I really don't understand what you're talking about with the scrollbar.
I picked up the color Scrollbar from http://tntluoma.com/sidebars/triplecolors/ I have a few other color links too. I guess I can create a program that will convert the named color into hex. I was hoping there was a less time consuming way to do it. Still, I don't need to write a line for each named color out there; just the ones I am most likely to use. Because I was trying to think of a shortcut the idea didn't even occur to me to write a script that would convert the named color codes individually, so your suggestion is really quite helpful. Often times answers like that will be right under my nose and I still won't see it.
why would a CSS property give you an image? I guess it wouldn't. I was hoping there might be a way to use CSS with php to make an image somehow. However I think you can get a screen capture (http://us3.php.net/manual/en/function.imagegrabscreen.php) with PHP. That may only be true if php is being run client side though. I don't know. I have not been interested enough to play around with it.
djr33
10-11-2009, 03:33 AM
There won't be a way to get an image from the user, because that would be a security issue, unless you just asked them to upload it. (Or you could do a screencapture yourself if you want...)
I understand now about obscure colors. For that, you will just need a list (ie, an array) with all of the possible named-colors. I've seen lists like this in various places, so just google for them and see which one is easiest to batch process.
However, if scrollbar is the color of the scrollbars on any given system (ie, varies by user), then this value will not be available at all through PHP, because it is a client side value. And considering that it is a named entity, I don't know of any way that you can use Ajax to get a number and send it back, etc. You could of course use a javascript approach to the problem, but that won't get it into php if you need it there for some reason (like image manipulation).
The only idea that seems possible is using that color in javascript, such as using something like colorsblend() if there is such a function available; clearly the browser will know the value and possibly finding it out by using color modification functions, IF they exist, would only then let you send it via Ajax to PHP and do what you need.
On the other hand, I can't think of a situation where you would actually NEED this (though it might be convenient). There are two options: 1. Use the named color in your layout as you need it. 2. If you are creating an image, you can use the named color as the background for that div/etc and then make a transparent .png that will go over it with alpha transparency for perfect blending. Of course you'd need to fix it for IE, but aside from that it would work fine.
The only limitation is that you can't design a layout around the scrollbar color, which could be conceivably a good idea, by making, for example, the background the scrollbar color, the borders a little lighter, and the text a little darker, all relative so it matches the browser window.
The only solution to this that you could implement automatically would be to check the user-agent string in the SERVER vars, and use that to determine the colors of the browser. It would not be entirely accurate, but it would give you a baseline for what, for example, Safari 3 on Windows Vista in the default configuration looks like, and go from there. Anyone who fakes a user-agent string or decides to customize their browser would get a non matching layout, but that's reasonable.
The problem, of course, is that you'd have to gather a database of colors for various environments-- this sounds like a useful public project, assuming there was interest.
james438
10-17-2009, 01:33 PM
Just for completeness I finished writing the script. It takes the background color and converts it from named or hexadecimal to decimal, like "red" or #FF0000; to 255, 0, 0 and uses this as the background. Then it takes the div color, converts it and I use it to create a filled arc. Basically I am creating a rounded corner. I then use a bit of ImageMagick to flip it horizontally and vertically and then I am done.
I hope that makes sense. I decided to use only the 20 most common colors I would use as opposed to adding the 200 or so different color names into an array. That would have been a little too tedious for me. I may still end up doing it later, but not now.
I used Opera to detect the color for "scrollbar" and used Opera's built in dev tools to convert the named color to its HTML equivalent and it created scrollbar is rgba(41, 16, 0, 0.505882). I am pretty sure that scrollbar is not referring to the user's current color scheme, which could conceivably be different for each user.
jscheuer1
10-17-2009, 04:33 PM
Actually those "System Colors" are entities of a sort (from the W3C):
18.2 System Colors
Note. The System Colors are deprecated in the CSS3 Color Module [CSS3COLOR].
In addition to being able to assign pre-defined color values to text, backgrounds, etc., CSS2 introduced a set of named color values that allows authors to specify colors in a manner that integrates them into the operating system's graphic environment.
For systems that do not have a corresponding value, the specified value should be mapped to the nearest system value, or to a default color.
The following lists additional values for color-related CSS properties and their general meaning. Any color property (e.g., 'color' or 'background-color') can take one of the following names. Although these are case-insensitive, it is recommended that the mixed capitalization shown below be used, to make the names more legible.
Basically this means that if your system (not your browser) has colors defined for these, they will be those colors, otherwise they will be default values or 'nearest' whatever nearest means.
I tired this out by changing my theme in Windows (right click on the desktop, choose properties, choose themes - don't do this if you haven't saved your current theme and know where your desktop background image is - otherwise you may lose those). Now normally I have a gray based theme with a sunset for the desktop image. All the system colors on that page where they are listed and shown were shades of gray or white. I changed my theme to Windows Default (which has a lot of blue in it) and many of the system colors on that page changed to shades of blue. But many which perhaps should have changed did not, this whole scheme was worked out before gradient colors were employed for many system objects, so those ones were just default - and wouldn't look good together on a page in many cases with the ones that did change with the system theme setting. So I consider this a wholly unreliable method for setting colors on your page.
Also, in either theme, some of the colors on the system colors page made the text that named them illegible. This is perhaps an even more important reason for not using these colors.
james438
10-18-2009, 12:31 AM
Thanks, that was very helpful. When looking at the list of colors I should have just kept reading.
Here is the link for the quote you posted. http://www.w3.org/TR/css3-color/#css-system
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.