]> git.mxchange.org Git - friendica.git/blob - php/PHPColors/README.md
first files - move to Version 0.1
[friendica.git] / php / PHPColors / README.md
1 ### Last Build: [![Build Status](https://secure.travis-ci.org/mexitek/phpColors.png)](http://travis-ci.org/mexitek/phpColors)
2
3 ## Installation
4
5 ### Composer
6
7 Simply add `mexitek/phpcolors` to `composer.json` using `dev-master`.
8
9 `composer require mexitek/phpcolors dev-master`
10
11 ## How it works
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.
13
14 ## Available Methods
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.
25
26 > Auto lightens/darkens by 10% for sexily-subtle gradients
27
28 ```php
29 /**
30  * Using The Class
31  */
32
33 use Mexitek\PHPColors\Color;
34
35 // Initialize my color
36 $myBlue = new Color("#336699");
37
38 echo $myBlue->darken();
39 // 1a334d
40
41 echo $myBlue->lighten();
42 // 8cb3d9
43
44 echo $myBlue->isLight();
45 // false
46
47 echo $myBlue->isDark();
48 // true
49
50 echo $myBlue->complementary();
51 // 996633
52
53 echo $myBlue->getHex();
54 // 336699
55
56 print_r( $myBlue->getHsl() );
57 // array( "H"=> 210, "S"=> 0.5, "L"=>0.4 );
58
59 print_r( $myBlue->getRgb() );
60 // array( "R"=> 51, "G"=> 102, "B"=>153 );
61
62 print_r($myBlue->makeGradient());
63 // array( "light"=>"8cb3d9" ,"dark"=>"336699" )
64
65 ```
66
67
68 ## Static Methods
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.
73
74 ```php
75 /**
76  * On The Fly Custom Calculations
77  */
78
79 use Mexitek\PHPColors\Color;
80
81  // Convert my HEX
82  $myBlue = Color::hexToHsl("#336699");
83
84  // Get crazy with the HUE
85  $myBlue["H"] = 295;
86
87  // Gimme my new color!!
88  echo Color::hslToHex($myBlue);
89  // 913399
90
91 ```
92
93 ## CSS Helpers
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.
95
96 > Would like to add support to custom gradient stops
97
98 ```php
99
100 use Mexitek\PHPColors\Color;
101
102 // Initialize my color
103 $myBlue = new Color("#336699");
104
105 // Get CSS
106 echo $myBlue->getCssGradient();
107 /* - Actual output doesn't have comments and is single line
108
109   // fallback background
110   background: #336699;
111
112   // IE Browsers
113   filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8cb3d9', endColorstr='#336699'); 
114  
115   // Safari 5.1+, Mobile Safari, Chrome 10+
116   background-image: -webkit-linear-gradient(top, #8cb3d9, #336699);
117
118   // Standards
119   background-image: linear-gradient(to bottom, #8cb3d9, #336699);
120
121 */
122
123 ```
124
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:
126
127 ```php
128
129 use Mexitek\PHPColors\Color;
130 $myBlue = new Color("#336699");
131
132 // Get CSS
133 echo $myBlue->getCssGradient(10, TRUE);
134 /* - Actual output doesn't have comments and is single line
135   
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
143
144 */
145
146 ```
147
148 ## Github Contributors
149 - mexitek
150 - danielpataki
151 - alexmglover
152 - intuxicated 
153 - pborreli
154 - curtisgibby
155 - matthewpatterson
156 - there4
157 - alex-humphreys
158 - zaher
159 - primozcigler
160 - thedavidmeister
161
162 # License: [arlo.mit-license.org](http://arlo.mit-license.org)