1 ### Last Build: [![Build Status](https://secure.travis-ci.org/mexitek/phpColors.png)](http://travis-ci.org/mexitek/phpColors)
7 Simply add `mexitek/phpcolors` to `composer.json` using `dev-master`.
9 `composer require mexitek/phpcolors dev-master`
12 Instantiate an object of the color class with a hex color string `$foo = new Color("336699")`. That's it! Now, call the methods you need for different color variants.
15 - <strong>darken( [$amount] )</strong> : Allows you to obtain a darker shade of your color. Optionally you can decide to darken using a desired percentage.
16 - <strong>lighten( [$amount] )</strong> : Allows you to obtain a lighter shade of your color. Optionally you can decide to lighten using a desired percentage.
17 - <strong>mix($hex, [$amount] )</strong> : Allows you to mix another color to your color. Optionally you can decide to set the percent of second color or original color amount is ranged -100..0.100.
18 - <strong>isLight( [$hex] )</strong> : Determins whether your color (or the provide param) is considered a "light" color. Returns `TRUE` if color is light.
19 - <strong>isDark( [$hex] )</strong> : Determins whether your color (or the provide param) is considered a "dark" color. Returns `TRUE` if color is dark.
20 - <strong>makeGradient( [$amount] )</strong> : Returns an array with 2 indices `light` and `dark`, the initial color will either be selected for `light` or `dark` depending on its brightness, then the other color will be generated. The optional param allows for a static lighten or darkened amount.
21 - <strong>complementary()</strong> : Returns the color "opposite" or complementary to your color.
22 - <strong>getHex()</strong> : Returns the original hex color.
23 - <strong>getHsl()</strong> : Returns HSL array for your color.
24 - <strong>getRgb()</strong> : Returns RGB array for your color.
26 > Auto lightens/darkens by 10% for sexily-subtle gradients
33 use Mexitek\PHPColors\Color;
35 // Initialize my color
36 $myBlue = new Color("#336699");
38 echo $myBlue->darken();
41 echo $myBlue->lighten();
44 echo $myBlue->isLight();
47 echo $myBlue->isDark();
50 echo $myBlue->complementary();
53 echo $myBlue->getHex();
56 print_r( $myBlue->getHsl() );
57 // array( "H"=> 210, "S"=> 0.5, "L"=>0.4 );
59 print_r( $myBlue->getRgb() );
60 // array( "R"=> 51, "G"=> 102, "B"=>153 );
62 print_r($myBlue->makeGradient());
63 // array( "light"=>"8cb3d9" ,"dark"=>"336699" )
69 - <strong>hslToHex( $hsl )</strong> : Convert a HSL array to a HEX string.
70 - <strong>hexToHsl( $hex )</strong> : Convert a HEX string into an HSL array.
71 - <strong>hexToRgb( $hex )</strong> : Convert a HEX string into an RGB array.
72 - <strong>rgbToHex( $rgb )</strong> : Convert an RGB array into a HEX string.
76 * On The Fly Custom Calculations
79 use Mexitek\PHPColors\Color;
82 $myBlue = Color::hexToHsl("#336699");
84 // Get crazy with the HUE
87 // Gimme my new color!!
88 echo Color::hslToHex($myBlue);
94 - <strong>getCssGradient( [$amount] [, $vintageBrowsers] )</strong> : Generates the CSS3 gradients for safari, chrome, opera, firefox and IE10. Optional percentage amount for lighter/darker shade. Optional boolean for older gradient CSS support.
96 > Would like to add support to custom gradient stops
100 use Mexitek\PHPColors\Color;
102 // Initialize my color
103 $myBlue = new Color("#336699");
106 echo $myBlue->getCssGradient();
107 /* - Actual output doesn't have comments and is single line
109 // fallback background
113 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699');
115 // Safari 5.1+, Mobile Safari, Chrome 10+
116 background-image: -webkit-linear-gradient(top, #8cb3d9, #336699);
119 background-image: linear-gradient(to bottom, #8cb3d9, #336699);
125 However, if you want to support the ancient browsers (which has negligible market share and almost died out), you can set the second parameter to `TRUE`. This will output:
129 use Mexitek\PHPColors\Color;
130 $myBlue = new Color("#336699");
133 echo $myBlue->getCssGradient(10, TRUE);
134 /* - Actual output doesn't have comments and is single line
136 background: #336699; // fallback background
137 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699'); // IE Browsers
138 background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#8cb3d9), to(#336699)); // Safari 4+, Chrome 1-9
139 background-image: -webkit-linear-gradient(top, #8cb3d9, #336699); // Safari 5.1+, Mobile Safari, Chrome 10+
140 background-image: -moz-linear-gradient(top, #8cb3d9, #336699); // Firefox 3.6+
141 background-image: -o-linear-gradient(top, #8cb3d9, #336699); // Opera 11.10+
142 background-image: linear-gradient(to bottom, #8cb3d9, #336699); // Standards
148 ## Github Contributors
162 # License: [arlo.mit-license.org](http://arlo.mit-license.org)