Niouzes

< Août 2018 >
Lu Ma Me Je Ve Sa Di
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Citation

Attention

The documentation is incomplete. The Vae Soli! team works hard to make it as exhaustive as possible with tons of useful examples and easy to understand explanations.

On top of that, we have decided to use our own tool to generate the documentation you read. This also takes time to fine-tune. Our goal is have better documentation, easier to read, easier to use, completely integrated with our site.

Even though NOT finalized, you can now link back to our documentation pages as we have decided once and for all about the structure of our documents and where they all reside on our server.

Thank you very much
The Vae Soli! team.

2018-08-20 à 07:03:02

Table Of Contents

  1. FOUNDATION (functions) (01/04/2015)
  2. LSAction (class) (01/04/2015)
  3. LSAddress (class) (01/04/2015)
  4. LSAdministrativeArea (class) (01/04/2015)
  5. LSApplication (class) (14/10/2013)
  6. LSArray (class) (14/10/2013)
  7. LSArticle (class) (18/02/2014)
  8. LSAssertion (class) (14/10/2013)
  9. LSAudience (class) (18/02/2014)
  10. AUTOLOAD (function) (21/04/2014)
  11. LSAutoReference (class) (14/10/2013)
  12. LSBag (class) (14/10/2013)
  13. LSBBCodes (class) (10/06/2014)
  14. LSBrowser (class) (14/10/2013)
  15. LSCache (class) (14/10/2013)
  16. LSCalculator (class) (14/10/2013)
  17. LSCalendar (class) (14/10/2013)
  18. LSCameraSnapshot (class) (14/10/2013)
  19. LSCitation (class) (14/10/2013)
  20. LSClass (class) (14/10/2013)
  21. LSCode (class) ()
  22. Colors (functions) (20/08/2018)
  23. LSContactForm (class) (14/10/2013)
  24. LSContainer (class) (14/10/2013)
  25. LSContents (class) (14/10/2013)
  26. LSContentsAccounts (class) (14/10/2013)
  27. LSContentsArticles (class) (14/10/2013)
  28. LSContentsAtomicClock (class) (14/10/2013)
  29. LSContentsBusinessCoordinates (class) (14/10/2013)
  30. LSContentsBusinessOff (class) (14/10/2013)
  31. LSContentsBusinessOpeningHours (class) (14/10/2013)
  32. LSContentsBreadcrumb (class) (14/10/2013)
  33. LSContentsCalendar (class) (14/10/2013)
  34. LSContentsCatalogue (class) (14/10/2013)
  35. LSContentsCharter (class) (18/02/2014)
  36. LSContentsCitation (class) (14/10/2013)
  37. LSContentsClock (class) (14/10/2013)
  38. LSContentsComments (class) (14/10/2013)
  39. LSContentsCookieUsage (class) (14/10/2013)
  40. LSContentsCountdown (class) (14/10/2013)
  41. LSContentsDatetime (class) (14/10/2013)
  42. LSContentsHeartbeat (class) (14/10/2013)
  43. LSContentsIFrame (class) (14/10/2013)
  44. LSContentsImageGallery (class) (14/10/2013)
  45. LSContentsLanguageSwitchers (class) (14/10/2013)
  46. LSContentsLegal (class) (18/02/2014)
  47. LSContentsMicronews (class) (14/10/2013)
  48. LSContentsMyAccount (class) (14/10/2013)
  49. LSContentsPaymentOptions (class) (14/10/2013)
  50. LSContentsPinboard (class) (14/10/2013)
  51. LSContentsRememberPassword (class) (14/10/2013)
  52. LSContentsRSS (class) (14/10/2013)
  53. LSContentsSiteManager (class) (14/10/2013)
  54. LSContentsSitemap (class) (14/10/2013)
  55. LSContentsShare (class) (14/10/2013)
  56. LSContentsStopwatch (class) (14/10/2013)
  57. LSContentsTagCloud (class) (14/10/2013)
  58. LSContentsTodosOnPage (class) (14/10/2013)
  59. LSContentsW3C (class) (14/10/2013)
  60. LSContentsWeather (class) (14/10/2013)
  61. LSControl (class) (14/10/2013)
  62. LSCreativeWork (class) (18/02/2014)
  63. LSCursor (class) (09/03/2015)
  64. LSCustomer (class) (14/10/2013)
  65. LSDataEnvironment (class) (14/10/2013)
  66. Dates (functions) (01/04/2015)
  67. LSDate (class) (14/10/2013)
  68. LSDictionary (class) (14/10/2013)
  69. LSDom, LSDomNode and LSXPath (class) (30/04/2014)
  70. LSErrors and LSError (classes) (14/10/2013)
  71. LSException (class) (16/10/2013)
  72. LSExplorer (class) (14/10/2013)
  73. LSFieldset (class) (14/10/2013)
  74. LSFile (class) (14/10/2013)
  75. LSFileProperties (class) (14/10/2013)
  76. Files (functions) (01/04/2015)
  77. Finance (functions) (01/04/2015)
  78. LSFootnotes (class) (22/02/2014)
  79. LSForm (class) (09/06/2014)
  80. LSFunction (class) (14/10/2013)
  81. LSGeorama (class) (24/10/2013)
  82. LSGeoramaVar (class) (24/10/2013)
  83. LSGlossary (class) (09/03/2015)
  84. LSGroup (class) (14/10/2013)
  85. HTML (functions) (01/04/2015)
  86. LSHttp (class) (14/10/2013)
  87. HTTP (functions) (01/04/2015)
  88. LSImageGallery (class) (14/10/2013)
  89. Images (functions) (01/04/2015)
  90. LSInput (class) (26/04/2014)
  91. IP (functions) (01/04/2015)
  92. LSIslandAbstract (14/10/2013)
  93. LSIslandFormAbstract (class) (14/10/2013)
  94. LSLabel (class) (14/10/2013)
  95. LSLanguageSwitchers (class) (14/10/2013)
  96. LSLatin (class) (14/10/2013)
  97. LSLegalPerson (class) (14/10/2013)
  98. LSLinkedList (class) (14/10/2013)
  99. LSList (class) (14/10/2013)
  100. Mails (functions) (01/04/2015)
  101. LSMap (class) (14/10/2013)
  102. Math (functions) (01/04/2015)
  103. LSMicronews (class) (18/02/2014)
  104. Miscellaneous (functions) (01/04/2015)
  105. LSModuleAbstract (class) (14/10/2013)
  106. LSNaturalPerson (class) (14/10/2013)
  107. LSNewsArticle (class) (18/02/2014)
  108. LSNote (class) (14/10/2013)
  109. LSMotherNature (class) (16/10/2013)
  110. LSPage (class) (18/02/2014)
  111. LSParameter (class) (14/10/2013)
  112. LSPaymentOptions (class) (14/10/2013)
  113. LSPeopleAudience (class) (18/02/2014)
  114. LSPerson (class) (14/10/2013)
  115. LSPlace (class) (18/02/2014)
  116. LSProperty (class) (14/10/2013)
  117. LSPublication (class) (14/10/2013)
  118. LSRequirement (class) (14/10/2013)
  119. LSReturn (class) (24/10/2013)
  120. LSRisk (class) (14/10/2013)
  121. LSSentanaiAbstract (14/10/2013)
  122. LSServiceMessage (class) (14/10/2013)
  123. LSSession (class) (14/10/2013)
  124. LSSiteManager (class) (14/10/2013)
  125. LSSitemap (class) (14/10/2013)
  126. LSSockets (class) (14/10/2013)
  127. LSSoftwareApplication (class) (18/02/2014)
  128. LSSource (class) (14/10/2013)
  129. Strings (functions) (31/07/2016)
  130. LSSupplier (class) (14/10/2013)
  131. System (functions) (01/04/2015)
  132. LSTag (class) (21/04/2014)
  133. LSTagCloud (class) (14/10/2013)
  134. LSTechArticle (class) (18/02/2014)
  135. LSThing (class) (18/02/2014)
  136. LSTimeline (class) (14/10/2013)
  137. LSTimer (class) (16/10/2013)
  138. LSTracer (class) (09/03/2015)
  139. LSUnitTesting (class) (14/10/2013)
  140. URL (functions) (01/04/2015)
  141. LSUser (class) (09/03/2015)
  142. LSUserMgr (class) (14/10/2013)
  143. LSVaesoli (class) (09/06/2014)
  144. LSVersion (class) (14/10/2013)
  145. LSWebSite (class) (14/10/2013)
  146. LSWidget (class) (14/10/2013)
  147. LSWireTransferForm (class) (14/10/2013)
  148. LSXMLSitemap (class) (14/10/2013)
  149. XML (functions) (01/04/2015)

LSColors.functions.php

Generated by The Vae Soli! Documentor: Guide v. 1.3.0018 on 20-08-2018 07:03:02 (DD-MM-YYYY HH:mm:SS). This documentation is built with Vae Soli! functions and classes!

The download page of Vae Soli! contains all sources of the framework.

Additional samples are available on the samples page of Vae Soli!.

File Properties

D:\websites\vaesoli.org\www\httpdocs/vaesoli/include/LSColors.functions.phpD:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSColors.functions.phpapplication/force-downloadD:\websites\vaesoli.org\www\httpdocs\vaesoli\include58145 bytes09/03/2016 09:52:4821/04/2018 11:45:0609/03/2016 09:52:48

Compliance

Assertions count: 48

Assertions successful: 48

Assertion failures: 0

Early Warning

LSColors.functions.php exceeds 51200 bytes. We suggest this file got broken down in smaller chunks!

LSColors.functions.php contains 1615 lines of code, which exceeds the suggested limit of 1024 lines. We suggest this file got broken down in smaller chunks!

0001 ... <?php
0002 ... /**************************************************************************/
0003 ... /** {{{*fheader
0004 ...     {*file                  LSColor.functions.php *}
0005 ...     {*purpose               Color oriented functions *}
0006 ...     {*author                 *}
0007 ...     {*company               Lato Sensu Management[br]
0008 ...                             Rue Bois des Mazuis, 47[br]
0009 ...                             5070 Vitrival[br]
0010 ...                             Belgium (BE)[br]
0011 ...                             http://www.latosensu.be[br]
0012 ...                             Vae Soli! : http://www.vaesoli.org *}
0013 ...     {*cdate                 11/11/2006 - 11:13 *}
0014 ...     {*mdate                 auto *}
0015 ...     {*license               [url]http://creativecommons.org/licenses/by-sa/2.0/be/[/url][br]
0016 ... 
0017 ...                             To obtain detailed information about the license
0018 ...                             terms, please head to the full license text
0019 ...                             available in the [file]LSCopyright.php[/file] file *}
0020 ... 
0021 ...     {*doc                   More info on
0022 ...                             [url]http://www.latosensu.be/articles/core/gestion-des-couleurs[/url].
0023 ...     *}
0024 ... 
0025 ... 
0026 ...     {*todo                  More functions to document *}
0027 ...     ------------------------------------------------------------------------
0028 ...     Changes History:
0029 ... 
0030 ...     [include]C:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSColors.functions.journal[/include]
0031 ... 
0032 ...     *}}} */
0033 ... /**************************************************************************/
0034 ... if ( ! defined( 'LS_COLOR_FUNCTIONS_PWH' ) )
0035 ... {
0036 ...     /* {*define (LS_COLOR_FUNCTIONS_PWH)  Remember that THESE functions have been declared *} */
0037 ...     define( 'LS_COLOR_FUNCTIONS_PWH','PWH' );
0038 ... }   /* if ( ! defined( 'LS_COLOR_FUNCTIONS_PWH' ) ) */
0039 ... 
0040 ... if ( ! defined( 'VAESOLI_PATH' ) )
0041 ... {
0042 ...     /* {*define (VAESOLI_PATH)      Define the path where Vae Soli! is installed *} */
0043 ...     define( 'VAESOLI_PATH',__DIR__ );
0044 ... }   /* if ( ! defined( 'VAESOLI_PATH' ) ) */
0045 ... 
0046 ... if ( ! defined( 'VAESOLI_PLUGINS' ) )
0047 ... {
0048 ...     /* {*define (VAESOLI_PLUGINS)   Define the path where plugins are located *} */
0049 ...     define( 'VAESOLI_PLUGINS',VAESOLI_PATH . '/../plugins' );
0050 ... }   /* if ( ! defined( 'VAESOLI_PLUGINS' ) ) */
0051 ... 
0052 ... /* ====================================================================== */
0053 ... /** {{*COLOR_rgb2hex( $r,$g,$b )=
0054 ... 
0055 ...     Turns a RGB color to its HTML hexa counterpart
0056 ... 
0057 ...     {*params
0058 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0059 ...         $g  (int)       Integer of the green component
0060 ...         $b  (int)       Integer of the blue component
0061 ...     *}
0062 ... 
0063 ...      {*return
0064 ...         (string)    HTML color (hexadecimal value)
0065 ...     *}
0066 ... 
0067 ...     {*exec
0068 ...         echo '<p>' . COLOR_rgb2hex( 255,128,255 ) . '</p>'; // Prints "#ff80ff"
0069 ...     *}
0070 ... 
0071 ...     {*exec
0072 ...         echo '<p>' . COLOR_rgb2hex( array( 'r' => 255,'g' => 128,'b' => 255) ) . '</p>'; // Prints "#ff80ff"
0073 ...     *}
0074 ... 
0075 ...     {*assert
0076 ...         COLOR_rgb2hex( array( 'r' => 255,'g' => 128,'b' => 255 ) ) === '#ff80ff'
0077 ...     *}
0078 ... 
0079 ...     {*assert
0080 ...         COLOR_rgb2hex( 255,128,255 ) === '#ff80ff'
0081 ...     *}
0082 ... 
0083 ...     {*seealso
0084 ...         COLOR_rgb2hsl(), COLOR_int2rgb(), COLOR_int2rgb2()
0085 ...     *}
0086 ... 
0087 ...     *}}
0088 ...  */
0089 ... /* ====================================================================== */
0090 ... function COLOR_rgb2hex( $r,$g = null,$b = null )
0091 ... /*--------------------------------------------*/
0092 ... {
0093 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
0094 ...     {
0095 ...         $g = $r['g'];                                               /* Green component */
0096 ...         $b = $r['b'];                                               /* Blue component */
0097 ...         $r = $r['r'];                                               /* Red component */
0098 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
0099 ... 
0100 ...     return ( '#' . sprintf( '%02x',$r ) .
0101 ...                    sprintf( '%02x',$g ) .
0102 ...                    sprintf( '%02x',$b ) );
0103 ... }   /* End of function COLOR_rgb2hex() ====================================== */
0104 ... 
0105 ... /* ========================================================================== */
0106 ... /** {{*COLOR_Contrast( $aRGB_A,$aRGB_B )=
0107 ... 
0108 ...     Contrast ratio between 2 colors
0109 ... 
0110 ...     {*params
0111 ...         $aRGB_A     (array)     RGB associative array[br]
0112 ...                                 [c]r[/c] ... red value[br]
0113 ...                                 [c]g[/c] ... green value[br]
0114 ...                                 [c]b[/c] ... blue value[br]
0115 ...         $aRGB_B     (array)     RGB associative array[br]
0116 ...                                 [c]r[/c] ... red value[br]
0117 ...                                 [c]g[/c] ... green value[br]
0118 ...                                 [c]b[/c] ... blue value[br]
0119 ...     *}
0120 ... 
0121 ...     {*return
0122 ...         (float)     Contrast ratio
0123 ...     *}
0124 ... 
0125 ...     {*assert
0126 ...         COLOR_Contrast( array( 'r' => 255,'g' => 255,'b' => 255 ),array( 'r' => 0,'g' => 0,'b' => 0 ) ) === (float) 21
0127 ...     *}
0128 ... 
0129 ...     {*assert
0130 ...         COLOR_Contrast( array( 'r' => 255,'g' => 0,'b' => 0 ),array( 'r' => 0,'g' => 0,'b' => 0 ) ) === 5.252
0131 ...     *}
0132 ... 
0133 ...     {*doc
0134 ...         The highest contrast is [c]21[/c]; the lowest is [c]1[/c]. A contrast of
0135 ...         [c]5[/c] gives a AA level; a contrast of [c]7[/c] gives a AAA grade. See
0136 ...         Web Content Accessibility Guidelines 2.0:
0137 ...         [url]http://www.w3.org/TR/2007/WD-WCAG20-TECHS-20070517/Overview.html#G18[/url]
0138 ...     *}
0139 ... 
0140 ...     {*cdate 19/05/2013 19:30 *}
0141 ...     {*version 5.3.0002  *}
0142 ...     {*author  *}
0143 ... 
0144 ... 
0145 ...     {*exec
0146 ...         echo COLOR_Contrast( array( 'r' => 255,'g' => 255,'b' => 255 ),array( 'r' => 0,'g' => 0,'b' => 0 ) );
0147 ...     *}
0148 ... 
0149 ...     {*exec
0150 ...         echo COLOR_Contrast( array( 'r' => 255,'g' => 255,'b' => 255 ),array( 'r' => 255,'g' => 255,'b' => 255 ) );
0151 ...     *}
0152 ... 
0153 ...     *}}
0154 ...  */
0155 ... /* ========================================================================== */
0156 ... function COLOR_Contrast( $aRGB_A,$aRGB_B )
0157 ... /*--------------------------------------*/
0158 ... {
0159 ...     $fRsRGB_A   = $aRGB_A['r'] / 255;
0160 ...     $fGsRGB_A   = $aRGB_A['g'] / 255;
0161 ...     $fBsRGB_A   = $aRGB_A['g'] / 255;
0162 ... 
0163 ...     $fRsRGB_B   = $aRGB_B['r'] / 255;
0164 ...     $fGsRGB_B   = $aRGB_B['g'] / 255;
0165 ...     $fBsRGB_B   = $aRGB_B['g'] / 255;
0166 ... 
0167 ...     /* Treating RGB_A -------------------------------------------- */
0168 ...     if ( $fRsRGB_A <= 0.03928 )
0169 ...         $fRed_A = $fRsRGB_A / 12.92;
0170 ...     else
0171 ...         $fRed_A = pow( ( ( $fRsRGB_A + 0.055 ) / 1.055 ),2.4 );
0172 ... 
0173 ...     if ( $fGsRGB_A <= 0.03928 )
0174 ...         $fGreen_A = $fGsRGB_A / 12.92;
0175 ...     else
0176 ...         $fGreen_A = pow( ( ( $fGsRGB_A + 0.055 ) / 1.055 ),2.4 );
0177 ... 
0178 ...     if ( $fBsRGB_A <= 0.03928 )
0179 ...         $fBlue_A = $fBsRGB_A / 12.92;
0180 ...     else
0181 ...         $fBlue_A = pow( ( ( $fBsRGB_A + 0.055 ) / 1.055 ),2.4 );
0182 ... 
0183 ...     $fL_A = ( 0.2126 * $fRed_A   ) +
0184 ...             ( 0.7152 * $fGreen_A ) +
0185 ...             ( 0.0722 * $fBlue_A  );
0186 ... 
0187 ...     /* Treating RGB_B -------------------------------------------- */
0188 ...     if ( $fRsRGB_B <= 0.03928 )
0189 ...         $fRed_B = $fRsRGB_B / 12.92;
0190 ...     else
0191 ...         $fRed_B = pow( ( ( $fRsRGB_B + 0.055 ) / 1.055 ),2.4 );
0192 ... 
0193 ...     if ( $fGsRGB_B <= 0.03928 )
0194 ...         $fGreen_B = $fGsRGB_B / 12.92;
0195 ...     else
0196 ...         $fGreen_B = pow( ( ( $fGsRGB_B + 0.055 ) / 1.055 ),2.4 );
0197 ... 
0198 ...     if ( $fBsRGB_B <= 0.03928 )
0199 ...         $fBlue_B = $fBsRGB_B / 12.92;
0200 ...     else
0201 ...         $fBlue_B = pow( ( ( $fBsRGB_B + 0.055 ) / 1.055 ),2.4 );
0202 ... 
0203 ...     $fL_B = ( 0.2126 * $fRed_B   ) +
0204 ...             ( 0.7152 * $fGreen_B ) +
0205 ...             ( 0.0722 * $fBlue_B  );
0206 ... 
0207 ...     return ( max( ( $fL_A + 0.05 ) / ( $fL_B + 0.05 ),
0208 ...                   ( $fL_B + 0.05 ) / ( $fL_A + 0.05 )
0209 ...                 )
0210 ...            );
0211 ... }   /* End of function COLOR_Contrast() ===================================== */
0212 ... 
0213 ... /* ========================================================================== */
0214 ... /** {{*COLOR_hex2rgb( $h )= Turns a hex color into RGB parts
0215 ... 
0216 ...     {*params
0217 ...         $h  (string)    Hexadecimal color (e.g. #ffffff)
0218 ...     *}
0219 ... 
0220 ...     {*return
0221 ...         (array)     RGB associative array[br]
0222 ...                     [c]r[/c]   … red value[br]
0223 ...                     [c]g[/c]   … green value[br]
0224 ...                     [c]b[/c]   … blue value[br]
0225 ...     *}
0226 ... 
0227 ...     {*exec
0228 ...         var_dump( $aRGB = COLOR_hex2rgb( '#ff80ff' ) );
0229 ...     *}
0230 ... 
0231 ...     {*assert
0232 ...         COLOR_hex2rgb( '#000000' ) === array( 'r' => 0,'g' => 0,'b' => 0 )
0233 ...     *}
0234 ... 
0235 ...     {*assert
0236 ...         COLOR_hex2rgb( '#ffffff' ) === array( 'r' => 255,'g' => 255,'b' => 255 )
0237 ...     *}
0238 ... 
0239 ...     {*assert
0240 ...         COLOR_hex2rgb( '#405060' ) === array( 'r' => 64,'g' => 80,'b' => 96 )
0241 ...     *}
0242 ... 
0243 ...     {*seealso
0244 ...         COLOR_rgb2hsl(), COLOR_int2rgb()
0245 ...     *}
0246 ... 
0247 ...     *}}
0248 ...  */
0249 ... /* ========================================================================== */
0250 ... function COLOR_hex2rgb( $h )
0251 ... /*------------------------*/
0252 ... {
0253 ...     return ( array( 'r' => hexdec( substr( $h, 1, 2 ) ),
0254 ...                     'g' => hexdec( substr( $h, 3, 2 ) ),
0255 ...                     'b' => hexdec( substr( $h, 5, 2 ) )
0256 ...                   ) );
0257 ... }   /* End of function COLOR_hex2rgb() ====================================== */
0258 ... 
0259 ... /* ========================================================================== */
0260 ... /** {{*COLOR_Luminosity( $r,$g,$b )=
0261 ... 
0262 ...     Returns color luminosity
0263 ... 
0264 ...     {*params
0265 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0266 ...         $g  (int)       Integer of the green component
0267 ...         $b  (int)       Integer of the blue component
0268 ...     *}
0269 ... 
0270 ...     {*return
0271 ...         (int)   Luminosity (value between 0 (dark) and 1 (max lumininosity)
0272 ...     *}
0273 ... 
0274 ...     {*assert
0275 ...         round( COLOR_Luminosity( 255,128,255 ),3 ) === 0.751
0276 ...     *}
0277 ... 
0278 ...     {*assert
0279 ...         round( COLOR_Luminosity( 255,0,255 ),3 ) === 0.5
0280 ...     *}
0281 ... 
0282 ...     {*assert
0283 ...         round( COLOR_Luminosity( 200,200,200 ),3 ) === 0.784
0284 ...     *}
0285 ... 
0286 ...     {*assert
0287 ...         round( COLOR_Luminosity( 0,0,255 ),3 ) === 0.5
0288 ...     *}
0289 ... 
0290 ...     {*example
0291 ...         Example #1
0292 ...         echo COLOR_Luminosity( 255,128,255 );   // Prints 0.75098039215686
0293 ... 
0294 ...         Example #2
0295 ...         echo COLOR_Luminosity( 160,120,255 );   // Prints 0.73529411764706
0296 ...     *}
0297 ... 
0298 ...     *}}
0299 ...  */
0300 ... /* ========================================================================== */
0301 ... function COLOR_Luminosity( $r,$g = null,$b = null )
0302 ... /*-----------------------------------------------*/
0303 ... {
0304 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
0305 ...     {
0306 ...         $g = $r['g'];                                               /* Green component */
0307 ...         $b = $r['b'];                                               /* Blue component */
0308 ...         $r = $r['r'];                                               /* Red component */
0309 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
0310 ... 
0311 ...     $r /= 255; $g /= 255; $b /= 255;                                /* Colors in percentage */
0312 ... 
0313 ...     $iMin = min( $r,$g,$b );                                        /* Min. value of RGB */
0314 ...     $iMax = max( $r,$g,$b );                                        /* Max. value of RGB */
0315 ... 
0316 ...     return ( ( $iMax + $iMin ) / 2 );                               /* Return result now */
0317 ... }   /* End of function COLOR_Luminosity() =================================== */
0318 ... 
0319 ... 
0320 ... /* ========================================================================== */
0321 ... /** {{*COLOR_KelvinToRGB( $r,$g,$b,$k )=
0322 ... 
0323 ...     Returns RGB value corresponding to a given temperature
0324 ... 
0325 ...     {*params
0326 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0327 ...         $g  (int)       Integer of the green component if $r not array
0328 ...         $b  (int)       Integer of the blue component if $r not array
0329 ...         $k  (int)       Temperature in Kelvin
0330 ...     *}
0331 ... 
0332 ...     {*return
0333 ...         (int)   Luminosity (value between 0 (dark) and 1 (max lumininosity)
0334 ...     *}
0335 ... 
0336 ...     {*assert
0337 ...         round( COLOR_Luminosity( 255,128,255 ),3 ) === 0.751
0338 ...     *}
0339 ... 
0340 ...     {*credits
0341 ...         [url]http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/[/url]
0342 ...     *}
0343 ... 
0344 ...     {*example
0345 ...         Example #1
0346 ...         echo COLOR_Luminosity( 255,128,255 );   // Prints 0.75098039215686
0347 ... 
0348 ...         Example #2
0349 ...         echo COLOR_Luminosity( 160,120,255 );   // Prints 0.73529411764706
0350 ...     *}
0351 ... 
0352 ...     *}}
0353 ...  */
0354 ... /* ========================================================================== */
0355 ... function COLOR_KelvinToRGB( $r,$g,$b,$k )
0356 ... /*-------------------------------------*/
0357 ... {
0358 ...     //'Given a temperature (in Kelvin), estimate an RGB equivalent
0359 ...     //Private Sub getRGBfromTemperature(ByRef r As Long, ByRef g As Long, ByRef b As Long, ByVal tmpKelvin As Long)
0360 ...     //
0361 ...     //    Static tmpCalc As Double
0362 ...     //
0363 ...     //    'Temperature must fall between 1000 and 40000 degrees
0364 ...     //    If tmpKelvin < 1000 Then tmpKelvin = 1000
0365 ...     //    If tmpKelvin > 40000 Then tmpKelvin = 40000
0366 ...     //    
0367 ...     //    'All calculations require tmpKelvin \ 100, so only do the conversion once
0368 ...     //    tmpKelvin = tmpKelvin \ 100
0369 ...     //    
0370 ...     //    'Calculate each color in turn
0371 ...     //    
0372 ...     //    'First: red
0373 ...     //    If tmpKelvin <= 66 Then
0374 ...     //        r = 255
0375 ...     //    Else
0376 ...     //        'Note: the R-squared value for this approximation is .988
0377 ...     //        tmpCalc = tmpKelvin - 60
0378 ...     //        tmpCalc = 329.698727446 * (tmpCalc ^ -0.1332047592)
0379 ...     //        r = tmpCalc
0380 ...     //        If r < 0 Then r = 0
0381 ...     //        If r > 255 Then r = 255
0382 ...     //    End If
0383 ...     //    
0384 ...     //    'Second: green
0385 ...     //    If tmpKelvin <= 66 Then
0386 ...     //        'Note: the R-squared value for this approximation is .996
0387 ...     //        tmpCalc = tmpKelvin
0388 ...     //        tmpCalc = 99.4708025861 * Log(tmpCalc) - 161.1195681661
0389 ...     //        g = tmpCalc
0390 ...     //        If g < 0 Then g = 0
0391 ...     //        If g > 255 Then g = 255
0392 ...     //    Else
0393 ...     //        'Note: the R-squared value for this approximation is .987
0394 ...     //        tmpCalc = tmpKelvin - 60
0395 ...     //        tmpCalc = 288.1221695283 * (tmpCalc ^ -0.0755148492)
0396 ...     //        g = tmpCalc
0397 ...     //        If g < 0 Then g = 0
0398 ...     //        If g > 255 Then g = 255
0399 ...     //    End If
0400 ...     //    
0401 ...     //    'Third: blue
0402 ...     //    If tmpKelvin >= 66 Then
0403 ...     //        b = 255
0404 ...     //    ElseIf tmpKelvin <= 19 Then
0405 ...     //        b = 0
0406 ...     //    Else
0407 ...     //        'Note: the R-squared value for this approximation is .998
0408 ...     //        tmpCalc = tmpKelvin - 10
0409 ...     //        tmpCalc = 138.5177312231 * Log(tmpCalc) - 305.0447927307
0410 ...     //        
0411 ...     //        b = tmpCalc
0412 ...     //        If b < 0 Then b = 0
0413 ...     //        If b > 255 Then b = 255
0414 ...     //    End If
0415 ...     //    
0416 ...     //End Sub
0417 ... }
0418 ... 
0419 ... /* ========================================================================== */
0420 ... /** {{*COLOR_Component( $r,$g,$b )=
0421 ... 
0422 ...     Returns the most important hue component (red,green or blue) of a given color
0423 ... 
0424 ...     {*params
0425 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0426 ...         $g  (int)       Integer of the green component. Optional if $r is an array.
0427 ...         $b  (int)       Integer of the blue component. Optional if $r is an array.
0428 ...     *}
0429 ... 
0430 ...     {*return
0431 ...         (char)  Letter indicating the most important tint: 'r', or 'g', or 'b'
0432 ...     *}
0433 ... 
0434 ...     {*caution
0435 ...                 In the case the tints are equal, red has precedence over
0436 ...                 green and blue, and green has precedence over blue
0437 ...     *}
0438 ... 
0439 ...     {*assert
0440 ...         COLOR_Component( 255,128,255 ) === "r"
0441 ...     *}
0442 ...     {*assert
0443 ...         COLOR_Component( 128,255,255 ) === "g"
0444 ...     *}
0445 ...     {*assert
0446 ...         COLOR_Component( 255,255,255 ) === "r"
0447 ...     *}
0448 ...     {*assert
0449 ...         COLOR_Component( 1,2,3 )       === "b"
0450 ...     *}
0451 ...     {*assert
0452 ...         COLOR_Component( array( 'r' => 1,'g' => 2,'b' => 3 ) ) === "b"
0453 ...     *}
0454 ... 
0455 ...     {*example
0456 ...         COLOR_Component( 255,128,255 ) -> "r"
0457 ...         COLOR_Component( 128,255,255 ) -> "g"
0458 ...         COLOR_Component( 255,255,255 ) -> "r"
0459 ...         COLOR_Component( 1,2,3 )       -> "b"
0460 ...     *}
0461 ... 
0462 ...     *}}
0463 ...  */
0464 ... /* ========================================================================== */
0465 ... function COLOR_Component(  $r,$g = null,$b = null )
0466 ... /*------------------------------------------------*/
0467 ... {
0468 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
0469 ...     {
0470 ...         $g = $r['g'];                                               /* Green component */
0471 ...         $b = $r['b'];                                               /* Blue component */
0472 ...         $r = $r['r'];                                               /* Red component */
0473 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
0474 ... 
0475 ...     if ( $r >= $g )                                                 /* If red is higher than green */
0476 ...     {
0477 ...         if ( $r >= $b )                                             /* If red is higher than blue */
0478 ...         {
0479 ...             return ( 'r' );                                         /* Return 'red' */
0480 ...         }   /* if ( $r >= $b ) */
0481 ...         else   /* Else of ... if ( $r >= $b ) */
0482 ...         {
0483 ...             return ( 'b' );                                         /* Return 'blue' */
0484 ...         }   /* End of ... Else of ... if ( $r >= $b ) */
0485 ...     }   /* if ( $r >= $g ) */
0486 ...     else   /* Else of ... if ( $r >= $g ) */
0487 ...     {
0488 ...         if ( $g >= $b )                                             /* If green higher than blue */
0489 ...         {
0490 ...             return ( 'g' );                                         /* Return 'green' */
0491 ...         }   /* if ( $g >= $b ) */
0492 ...         else   /* Else of ... if ( $g >= $b ) */
0493 ...         {
0494 ...             return ( 'b' );                                         /* Return 'blue' */
0495 ...         }   /* End of ... Else of ... if ( $g >= $b ) */
0496 ...     }   /* End of ... Else of ... if ( $r >= $g ) */
0497 ... }   /* End of function COLOR_Component() ==================================== */
0498 ... 
0499 ... /* ========================================================================== */
0500 ... /** {{*COLOR_Blend($rgb1,$rgb2,$iSteps )=
0501 ... 
0502 ...     Returns an array of intermediate color values between 2 colors
0503 ... 
0504 ...     {*params
0505 ...         $rgb1   (array)     Array of RGB colors (start value)
0506 ...         $rgb2   (array)     Array of RGB colors (end value)
0507 ...         $iSteps (int)       Number of steps between start and end
0508 ...     *}
0509 ... 
0510 ...     {*return
0511 ...         (array) Array of arrays (RGB colors)
0512 ...     *}
0513 ... 
0514 ...     {*exec
0515 ...         echo "This example generates the nice gradient below:\n\n";
0516 ... 
0517 ...         $szTag    = 'span';
0518 ...         $szPStyle = "display:inline-block;width:300px;background";
0519 ... 
0520 ...         $aRgb1 = array( 'r' => 255,'g' =>   0,'b' => 0 );
0521 ...         $aRgb2 = array( 'r' => 255,'g' => 255,'b' => 0 );
0522 ... 
0523 ...         $aRgbs  = COLOR_blend( $aRgb1,$aRgb2,20 );
0524 ...         $szRGBs = serialize( $aRgbs );
0525 ...         $szHTML = '';
0526 ... 
0527 ...         foreach( $aRgbs as $aRgb )
0528 ...         {
0529 ...             echo $szColorStrip = "<{$szTag} style=\"{$szPStyle}:rgb({$aRgb['r']},{$aRgb['g']},{$aRgb['b']});\">&#160;</{$szTag}>\n";
0530 ...             $szHTML .= $szColorStrip;
0531 ...         }
0532 ... 
0533 ...         echo LSUnitTesting::assert( $aRgbs[7]['r'] === 255  &&
0534 ...                                     $aRgbs[7]['g'] === 89   &&
0535 ...                                     $aRgbs[7]['b'] === 0    &&
0536 ...                                     count( $aRgbs ) === 21                          ,
0537 ...                                     'ASSERTION SUCCESS: Gotcha!'                    ,
0538 ...                                     'ASSERTION FAILURE: Houston, we have a problem!',
0539 ...                                     'GuideAssert' );
0540 ...    *}
0541 ... 
0542 ...     *}}
0543 ...  */
0544 ... /* ========================================================================== */
0545 ... function COLOR_blend( $rgb1,$rgb2,$iSteps )
0546 ... /*---------------------------------------*/
0547 ... {
0548 ...     $aRGBs  = array();                                              /* Create an empty array */
0549 ... 
0550 ...     array_push( $aRGBs,$rgb1 );                                     /* First value of the blend */
0551 ... 
0552 ...     for ( $i=1;$i<$iSteps;$i++ )                                    /* For the number of steps which are required */
0553 ...     {
0554 ...         $r = (int) abs( $rgb1['r'] + (int) ( ( ( ( $rgb2['r'] - $rgb1['r'] ) / $iSteps ) ) * $i ) );/* Compute Red value */
0555 ...         $g = (int) abs( $rgb1['g'] + (int) ( ( ( ( $rgb2['g'] - $rgb1['g'] ) / $iSteps ) ) * $i ) );/* Compute Green value */
0556 ...         $b = (int) abs( $rgb1['b'] + (int) ( ( ( ( $rgb2['b'] - $rgb1['b'] ) / $iSteps ) ) * $i ) );/* Compute Blue value */
0557 ... 
0558 ...         $r = ( $r > 255 ? 255 : $r );                               /* Adjust if out of bounds */
0559 ...         $g = ( $g > 255 ? 255 : $g );                               /* Adjust if out of bounds */
0560 ...         $b = ( $b > 255 ? 255 : $b );                               /* Adjust if out of bounds */
0561 ... 
0562 ...         array_push( $aRGBs,array( 'r' => $r,                        /* Push the array in the result array */
0563 ...                                   'g' => $g,
0564 ...                                   'b' => $b ) );
0565 ...     }   /* End of ... for ( $i=1;$i<$iSteps;$i++ ) */
0566 ... 
0567 ...     $n = count( $aRGBs );                                           /* How many elements in the result array? */
0568 ... 
0569 ...     if ( $rgb2['r'] != $aRGBs[$n-1]['r'] ||                         /* If we're not done yet */
0570 ...          $rgb2['g'] != $aRGBs[$n-1]['g'] ||
0571 ...          $rgb2['b'] != $aRGBs[$n-1]['b'] )
0572 ...     {
0573 ...         array_push( $aRGBs,$rgb2 );                                 /* Last value of the blending operation (endig color) */
0574 ...     }   /* End of ... if ( $rgb2['r'] != $aRGBs[$n-1]['r'] || ... */
0575 ... 
0576 ...     return ( $aRGBs );                                              /* Return the result array */
0577 ... }   /* End of function COLOR_blend() ======================================== */
0578 ... 
0579 ... /* ========================================================================== */
0580 ... /** {{*COLOR_rgb2int( $r,$g,$b )=
0581 ... 
0582 ...     Turns an RGB color into an integer
0583 ... 
0584 ...     {*params
0585 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0586 ...         $g  (int)       Integer of the green component if $r is an integer
0587 ...         $b  (int)       Integer of the blue component if $r is an integer
0588 ...     *}
0589 ... 
0590 ...     {*return
0591 ...         (int)   The resulting color as an integer
0592 ...     *}
0593 ... 
0594 ...     {*assert
0595 ...         COLOR_rgb2int( 255,255,255 ) === 16777215
0596 ...     *}
0597 ... 
0598 ...     {*assert
0599 ...         COLOR_rgb2int( 255,0,255   ) === 16711935
0600 ...     *}
0601 ... 
0602 ...     {*assert
0603 ...         COLOR_rgb2int( 0,255,255   ) === 16776960
0604 ...     *}
0605 ... 
0606 ...     {*assert
0607 ...         COLOR_rgb2int( 0,255,0     ) === 65280
0608 ...     *}
0609 ... 
0610 ...     {*assert
0611 ...         COLOR_rgb2int( 0,0,255     ) === 16711680
0612 ...     *}
0613 ... 
0614 ...     {*assert
0615 ...         COLOR_rgb2int( 255,0,255   ) === 16711935
0616 ...     *}
0617 ... 
0618 ...     {*exec
0619 ...         echo COLOR_rgb2int( 255,0,255 );
0620 ...     *}
0621 ... 
0622 ...     {*seealso
0623 ...         COLOR_int2rgb()
0624 ...     *}
0625 ... 
0626 ...     {*alias
0627 ...         COLOR_rgb(), rgb()
0628 ...     *}
0629 ...     *}}
0630 ...  */
0631 ... /* ========================================================================== */
0632 ... function COLOR_rgb2int( $r,$g = null,$b = null )
0633 ... /*--------------------------------------------*/
0634 ... {
0635 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
0636 ...     {
0637 ...         $g = $r['g'];                                               /* Green component */
0638 ...         $b = $r['b'];                                               /* Blue component */
0639 ...         $r = $r['r'];                                               /* Red component */
0640 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
0641 ... 
0642 ...     return ( ( $r * 1     ) +   /* ( 256 ^ 0 ) or ... pow( 256,0 ) */
0643 ...              ( $g * 256   ) +   /* ( 256 ^ 1 ) or ... pow( 256,1 ) */
0644 ...              ( $b * 65536 ) );  /* ( 256 ^ 2 ) or ... pow( 256,2 ) */
0645 ... }   /* End of function COLOR_rgb2int() ====================================== */
0646 ... function COLOR_rgb( $r,$g = null,$b = null ) { return ( COLOR_rgb2int( $r,$g,$b ) ); }
0647 ... function rgb(       $r,$g = null,$b = null ) { return ( COLOR_rgb2int( $r,$g,$b ) ); }
0648 ... 
0649 ... /* ========================================================================== */
0650 ... /** {{*COLOR_int2rgb( $x )=
0651 ... 
0652 ...     Turns an integer into a RGB color
0653 ... 
0654 ...     {*params
0655 ...         $x  (int)       Integer that must be turned to a RGB color
0656 ...     *}
0657 ... 
0658 ...     {*return
0659 ...         (array)      An associative array : 'r', 'g', 'b'
0660 ...     *}
0661 ... 
0662 ...     {*assert
0663 ...         COLOR_int2rgb( 7905535 ) === array( 'r' => 255,'g' => 160,'b' => 120 )
0664 ...     *}
0665 ... 
0666 ...     {*assert
0667 ...         COLOR_int2rgb( 15767160 ) === array( 'r' => 120,'g' => 150,'b' => 240 )
0668 ...     *}
0669 ... 
0670 ...     {*example
0671 ...         $iColor = COLOR_rgb2int( array( 'r' => 255,'g' => 160,'b' => 120 ) );
0672 ...     *}
0673 ... 
0674 ...     {*seealso
0675 ...         COLOR_rgb2int()
0676 ...     *}
0677 ... 
0678 ...     *}}
0679 ...  */
0680 ... /* ========================================================================== */
0681 ... function COLOR_int2rgb( $x )
0682 ... /*------------------------*/
0683 ... {
0684 ...     $b      = ( $x >> 16 ) & 0xFF;                                  /* Red in the image */
0685 ...     $g      = ( $x >> 8  ) & 0xFF;                                  /* Green in the image */
0686 ...     $r      =   $x         & 0xFF;                                  /* Blue in the image */
0687 ... 
0688 ...     return ( array( 'r' => $r   ,                                   /* Return RGB array to caller */
0689 ...                     'g' => $g   ,
0690 ...                     'b' => $b
0691 ...                    ) );
0692 ... }   /* End of function COLOR_int2rgb() ====================================== */
0693 ... 
0694 ... /* ========================================================================== */
0695 ... /** {{*COLOR_rgb2hsv( $r,$g,$b )=
0696 ... 
0697 ...     Turns an RGB color into hue, saturation and value
0698 ... 
0699 ...     {*params
0700 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0701 ...         $g  (int)       Integer of the green component if $r is an integer
0702 ...         $b  (int)       Integer of the blue component if $r is an integer
0703 ...     *}
0704 ... 
0705 ...     {*credits       Adapted from [url]http://www.easyrgb.com/math.php?MATH=M20#text20[/url]
0706 ...     *}
0707 ... 
0708 ...     {*return
0709 ...         (int)       The resulting color as an integer
0710 ...     *}
0711 ... 
0712 ...     {*doc           More doc on [url]http://www.latosensu.be/articles/core/gestion-des-couleurs/?part=5[/url].
0713 ...     *}
0714 ... 
0715 ...     {*example
0716 ...         Example #1
0717 ...         $aRGB = COLOR_hex2rgb( '#ff80ff' ); // $aRGB['r'] = 255,$aRGB['g'] = 128,$aRGB['b'] = 255
0718 ...     *}
0719 ... 
0720 ...     {*seealso
0721 ...         COLOR_int2rgb(), COLOR_int2rgb2()
0722 ...     *}
0723 ... 
0724 ...     {*alias
0725 ...         COLOR_rgb2hsb()
0726 ...     *}
0727 ... 
0728 ...     *}}
0729 ...  */
0730 ... /* ========================================================================== */
0731 ... function COLOR_rgb2hsv( $r,$g = null,$b = null )
0732 ... /*--------------------------------------------*/
0733 ... {
0734 ...     if ( is_array( $r ) && isset( $r['r'] ) )
0735 ...     {
0736 ...         $g = $r['g'];
0737 ...         $b = $r['b'];
0738 ...         $r = $r['r'];
0739 ...     }
0740 ... 
0741 ...     $r = ( $r / 255 );                                              //RGB values = 0 ÷ 255
0742 ...     $g = ( $g / 255 );
0743 ...     $b = ( $b / 255 );
0744 ... 
0745 ...     $iMin = min( $r,$g,$b );                                        //Min. value of RGB
0746 ...     $iMax = max( $r,$g,$b );                                        //Max. value of RGB
0747 ...     $delta = $iMax - $iMin;                                         //Delta RGB value
0748 ... 
0749 ...     $v = $iMax;
0750 ... 
0751 ...     if ( $delta == 0 )                                              //This is a gray, no chroma...
0752 ...     {
0753 ...         $h = $s = 0;                                                //HSV results = 0 ÷ 1
0754 ...     }
0755 ...     else                                                            //Chromatic data...
0756 ...     {
0757 ...         $s = $delta / $iMax;
0758 ... 
0759 ...         $delta_r = ( ( ( $iMax - $r ) / 6 ) + ( $delta / 2 ) ) / $delta;
0760 ...         $delta_g = ( ( ( $iMax - $g ) / 6 ) + ( $delta / 2 ) ) / $delta;
0761 ...         $delta_b = ( ( ( $iMax - $b ) / 6 ) + ( $delta / 2 ) ) / $delta;
0762 ... 
0763 ...         if      ( $r == $iMax ) $h = ( 0 / 3 ) + $delta_b - $delta_g;
0764 ...         else if ( $g == $iMax ) $h = ( 1 / 3 ) + $delta_r - $delta_b;
0765 ...         else if ( $b == $iMax ) $h = ( 2 / 3 ) + $delta_g - $delta_r;
0766 ... 
0767 ...         if ( $h < 0 )
0768 ...             $h += 1;
0769 ...         if ( $h > 1 )
0770 ...             $h -= 1;
0771 ...     }
0772 ... 
0773 ...     return ( array( 'h' => $h,
0774 ...                     's' => $s,
0775 ...                     'v' => $v
0776 ...                    ) );
0777 ... }   /* End of function COLOR_rgb2hsv() ====================================== */
0778 ... function COLOR_rgb2hsb( $r,$g = null,$b = null ) { return ( COLOR_rgb2hsv( $r,$g,$b ) ); }
0779 ... 
0780 ... /* ========================================================================== */
0781 ... /** {{*COLOR_hsv2rgb( $h[,$s[,$v]] )=
0782 ... 
0783 ...     Turns a HSV value into its RGB equivalent
0784 ... 
0785 ...     {*params
0786 ...         $h  (mixed)     Associative array ([c]h[/c],[c]s[/c],[c]v[/c]) or
0787 ...                             int. If int, $h is the hue value
0788 ...         $s  (int)       Saturation value. Used if $h is an int.
0789 ...         $v  (int)       value. Used if $h is an int.
0790 ...     *}
0791 ... 
0792 ...     {*credits
0793 ...         Adapted from [url]http://www.easyrgb.com/math.php?MATH=M20#text21[/url].
0794 ...     *}
0795 ... 
0796 ...     {*return
0797 ...         (int)       The resulting color as an RGB associative array
0798 ...     *}
0799 ... 
0800 ...     {*alias
0801 ...         COLOR_hsb2rgb()
0802 ...     *}
0803 ... 
0804 ...     *}}
0805 ...  */
0806 ... /* ========================================================================== */
0807 ... function COLOR_hsv2rgb( $h,$s = null,$v = null )
0808 ... /*--------------------------------------------*/
0809 ... {
0810 ...     if ( is_array( $h ) && isset( $h['v'] ) )
0811 ...     {
0812 ...         $s = $h['s'];
0813 ...         $v = $h['v'];
0814 ...         $h = $h['h'];
0815 ...     }
0816 ... 
0817 ...     if ( $s == 0 )                       //HSV values = 0 ÷ 1
0818 ...     {
0819 ...         $r = $g = $b = $v * 255;
0820 ...     }   /* if ( $s == 0 ) */
0821 ...     else
0822 ...     {
0823 ...         $h *= 6;
0824 ... 
0825 ...         if ( $h == 6 ) $h = 0;      //H must be < 1
0826 ... 
0827 ...         $var_i = (int) $h;             //Or ... var_i = floor( var_h )
0828 ...         $var_1 = $v * ( 1 - $s );
0829 ...         $var_2 = $v * ( 1 - $s * ( $h - $var_i ) );
0830 ...         $var_3 = $v * ( 1 - $s * ( 1 - ( $h - $var_i ) ) );
0831 ... 
0832 ...         if      ( $var_i == 0 ) { $r = $v     ; $g = $var_3 ; $b = $var_1 ; }
0833 ...         else if ( $var_i == 1 ) { $r = $var_2 ; $g = $v     ; $b = $var_1 ; }
0834 ...         else if ( $var_i == 2 ) { $r = $var_1 ; $g = $v     ; $b = $var_3 ; }
0835 ...         else if ( $var_i == 3 ) { $r = $var_1 ; $g = $var_2 ; $b = $v     ; }
0836 ...         else if ( $var_i == 4 ) { $r = $var_3 ; $g = $var_1 ; $b = $v     ; }
0837 ...         else                    { $r = $v     ; $g = $var_1 ; $b = $var_2 ; }
0838 ... 
0839 ...         $r *= 255;                  //RGB results = 0 ÷ 255
0840 ...         $g *= 255;
0841 ...         $b *= 255;
0842 ...     }
0843 ... 
0844 ...     return ( array( 'r' => (int) round( $r,0 ),
0845 ...                     'g' => (int) round( $g,0 ),
0846 ...                     'b' => (int) round( $b,0 )
0847 ...                    ) );
0848 ... }   /* End of function COLOR_hsv2rgb() ====================================== */
0849 ... function COLOR_hsb2rgb( $r,$g = null,$b = null ) { return ( COLOR_hsv2rgb( $r,$g,$b ) ); }
0850 ... 
0851 ... /* ========================================================================== */
0852 ... /** {{*COLOR_rgb2gray( $r[,$g[,$b]] )=
0853 ... 
0854 ...     Transforms a color into a grey flavor
0855 ... 
0856 ...     {*params
0857 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0858 ...         $g  (int)       Integer of the green component
0859 ...         $b  (int)       Integer of the blue component
0860 ...     *}
0861 ... 
0862 ...     {*return
0863 ...         (array)         The resulting color as an RGB associative array[br]
0864 ...                         [c]r[/c]   … red value[br]
0865 ...                         [c]g[/c]   … green value[br]
0866 ...                         [c]b[/c]   … blue value[br]
0867 ...     *}
0868 ... 
0869 ...     {*exec
0870 ...         $aRGB = COLOR_rgb2gray( 155,200,15 );
0871 ...         var_dump( $aRGB );
0872 ...         echo LSUnitTesting::assert( $aRGB['r'] === 165                      ,
0873 ...                                     'ASSERTION SUCCESS: gray tint correct'  ,
0874 ...                                     'ASSERTION SUCCESS: gray tint incorrect',
0875 ...                                     'GuideAssert' );
0876 ... 
0877 ...     *}
0878 ... 
0879 ...     *}}
0880 ...  */
0881 ... /* ========================================================================== */
0882 ... function COLOR_rgb2gray( $r,$g = null,$b = null )
0883 ... /*---------------------------------------------*/
0884 ... {
0885 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
0886 ...     {
0887 ...         $g = $r['g'];                                               /* Green component */
0888 ...         $b = $r['b'];                                               /* Blue component */
0889 ...         $r = $r['r'];                                               /* Red component */
0890 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
0891 ... 
0892 ...     $val = round( ( 0.299 * $r ) +
0893 ...                   ( 0.587 * $g ) +
0894 ...                   ( 0.114 * $b ) );
0895 ... 
0896 ...     return ( array( 'r' => (int) $val,
0897 ...                     'g' => (int) $val,
0898 ...                     'b' => (int) $val
0899 ...                   ) );
0900 ... }   /* End of function COLOR_rgb2gray() ===================================== */
0901 ... 
0902 ... /* ========================================================================== */
0903 ... /** {{*COLOR_hue( $r[,$g[,$b]] )=
0904 ... 
0905 ...     Returns the hue of a given color
0906 ... 
0907 ...     {*params
0908 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0909 ...         $g  (int)       Integer of the green component
0910 ...         $b  (int)       Integer of the blue component
0911 ...     *}
0912 ... 
0913 ...     {*return
0914 ...         (int)       The resulting hue
0915 ...     *}
0916 ... 
0917 ...     {*exec
0918 ...         [include]__DIR__/ut/hue.php[/include]
0919 ...     *}
0920 ... 
0921 ...     *}}
0922 ...  */
0923 ... /* ========================================================================== */
0924 ... function COLOR_hue( $r,$g = null,$b = null )
0925 ... /*----------------------------------------*/
0926 ... {
0927 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
0928 ...     {
0929 ...         $g = $r['g'];                                               /* Green component */
0930 ...         $b = $r['b'];                                               /* Blue component */
0931 ...         $r = $r['r'];                                               /* Red component */
0932 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
0933 ... 
0934 ...     $iMin   = min( $r,$g,$b );                                      /* What's the minimum of all three pigments */
0935 ...     $iMax   = max( $r,$g,$b );                                      /* What's the maximum of all three pigments */
0936 ...     $delta  = $iMax - $iMin;                                        /* Calculate delta */
0937 ... 
0938 ...     if ( $iMin == $iMax )
0939 ...     {
0940 ...         $h = -1;
0941 ...     }
0942 ...     else if ( ( $r == $iMax ) && ( $g >= $b ) )
0943 ...     {
0944 ...         //         g - b
0945 ...         // 60 x -----------
0946 ...         //       max - min
0947 ... 
0948 ...         $h = 60 * ( ( $g - $b ) / $delta );
0949 ...     }
0950 ...     else if ( ( $r == $iMax ) && ( $g < $b ) )
0951 ...     {
0952 ...         //         g - b
0953 ...         // 60 x ----------- + 360
0954 ...         //       max - min
0955 ... 
0956 ...         $h = 60 * ( ( $g - $b ) / $delta ) + 360;
0957 ...     }
0958 ...     else if ( $g == $iMax )
0959 ...     {
0960 ...         //         b - r
0961 ...         // 60 x ----------- + 120
0962 ...         //       max - min
0963 ... 
0964 ...         $h = 60 * ( ( $b - $r ) / $delta ) + 120;
0965 ...     }
0966 ...     else if ( $b == $iMax )
0967 ...     {
0968 ...         //         r - g
0969 ...         // 60 x ----------- + 240
0970 ...         //       max - min
0971 ... 
0972 ...         $h = 60 * ( ( $r - $g ) / $delta ) + 240;
0973 ...     }
0974 ... 
0975 ...     return ( $h );
0976 ... }   /* End of function COLOR_hue() ========================================== */
0977 ... 
0978 ... /* ========================================================================== */
0979 ... /** {{*COLOR_nadir( $r[,$g[,$b]] )=
0980 ... 
0981 ...     Returns the color right at the opposite of rgb( $r,$g,$b )
0982 ... 
0983 ...     {*params
0984 ...         $r  (mixed)     Array of RGB colors or integer of the red component
0985 ...         $g  (int)       Integer of the green component
0986 ...         $b  (int)       Integer of the blue component
0987 ...     *}
0988 ... 
0989 ...     {*return
0990 ...         (array)         RGB associative array[br]
0991 ...                         [c]r[/c]   … red value[br]
0992 ...                         [c]g[/c]   … green value[br]
0993 ...                         [c]b[/c]   … blue value[br]
0994 ...     *}
0995 ... 
0996 ...     {*exec
0997 ...         [include]__DIR__/ut/nadir.php[/include]
0998 ...     *}
0999 ... 
1000 ...     *}}
1001 ...  */
1002 ... /* ========================================================================== */
1003 ... function COLOR_nadir( $r,$g = null,$b = null )
1004 ... /*------------------------------------------*/
1005 ... {
1006 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
1007 ...     {
1008 ...         $g = $r['g'];                                               /* Green component */
1009 ...         $b = $r['b'];                                               /* Blue component */
1010 ...         $r = $r['r'];                                               /* Red component */
1011 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
1012 ... 
1013 ...     return ( array( 'r' => abs( 255 - $r ),
1014 ...                     'g' => abs( 255 - $g ),
1015 ...                     'b' => abs( 255 - $b ) ) );
1016 ... }   /* End of COLOR_nadir() ================================================= */
1017 ... 
1018 ... /* ========================================================================== */
1019 ... /** {{*COLOR_Complementary( $r,$g,$b,$degree )=
1020 ... 
1021 ...     Finds the complementary color of a given color
1022 ... 
1023 ...     {*params
1024 ...         $r          (mixed)     Array of RGB colors or integer of the red component
1025 ...         $g          (int)       Integer of the green component (if $r NOT array)
1026 ...         $b          (int)       Integer of the blue component (if $r NOT array)
1027 ...         $degree     (int)       Complementary color based on a given hue degree.
1028 ...                                 Optional. [c]180&deg;[/c] by default (nadir)
1029 ...     *}
1030 ... 
1031 ...     {*return
1032 ...         (array)     Resulting color as a RGB associative array[br]
1033 ...                         [c]r[/c]   … red value[br]
1034 ...                         [c]g[/c]   … green value[br]
1035 ...                         [c]b[/c]   … blue value[br]
1036 ...     *}
1037 ... 
1038 ...     {*credits
1039 ...         Adapted from [url]http://www.easyrgb.com/math.php?MATH=M11#text11[/url].
1040 ...     *}
1041 ... 
1042 ...     {*exec
1043 ...         var_dump( $aRGB = COLOR_Complementary( 100,150,200 ) );
1044 ... 
1045 ...         echo LSUnitTesting::assert( $aRGB['r'] == 200 &&
1046 ...                                     $aRGB['g'] == 150 &&
1047 ...                                     $aRGB['b'] == 100                                               ,
1048 ...                                     'ASSERTION SUCCESS: complementary color successfully calculated',
1049 ...                                     'ASSERTION FAILURE: unexpected complementary color'             ,
1050 ...                                     'GuideAssert' );
1051 ... 
1052 ...         var_dump( $aRGB = COLOR_Complementary( $aRGB ) );
1053 ... 
1054 ...         echo LSUnitTesting::assert( $aRGB['r'] == 100 &&
1055 ...                                     $aRGB['g'] == 150 &&
1056 ...                                     $aRGB['b'] == 200                                   ,
1057 ...                                     'ASSERTION SUCCESS: return to original on 180&deg;' ,
1058 ...                                     'ASSERTION FAILURE: unexpected complementary color' ,
1059 ...                                     'GuideAssert' );
1060 ... 
1061 ...         var_dump( $aRGB = COLOR_Complementary( $aRGB,null,null,100 ) );
1062 ... 
1063 ...         echo LSUnitTesting::assert( $aRGB['r'] == 200 &&
1064 ...                                     $aRGB['g'] == 100 &&
1065 ...                                     $aRGB['b'] == 183                                   ,
1066 ...                                     'ASSERTION SUCCESS: complementary on 100&deg;'      ,
1067 ...                                     'ASSERTION FAILURE: unexpected complementary color' ,
1068 ...                                     'GuideAssert' );
1069 ...     *}
1070 ... 
1071 ...     *}}
1072 ...  */
1073 ... /* ========================================================================== */
1074 ... function COLOR_Complementary( $r,$g = null,$b = null,$degree = 180 )
1075 ... /*----------------------------------------------------------------*/
1076 ... {
1077 ...     $hsl = COLOR_rgb2hsl( $r,$g,$b );                               /* Turn to HSL value */
1078 ... 
1079 ...     $hsl['h'] += ( $degree / 360 );                                 /* Change hue of a given degree */
1080 ... 
1081 ...     if ( $hsl['h'] > 1 )                                            /* If hue > 1 */
1082 ...     {
1083 ...         $hsl['h'] -= 1;                                             /* Decrease hue by 1 (this is a circle) */
1084 ...     }
1085 ... 
1086 ...     return ( COLOR_hsl2rgb( $hsl['h'],$hsl['s'],$hsl['l'] ) );      /* Turn hsl to rgb -- return result to caller */
1087 ... }   /* End of COLOR_complementary() ========================================= */
1088 ... 
1089 ... /* ========================================================================== */
1090 ... /** {{*COLOR_rgb2cmy( $r[,$g[,$b]] )=
1091 ... 
1092 ...     Transforms a color into a CMY associative array
1093 ... 
1094 ...     {*params
1095 ...         $r  (mixed)     Array of RGB colors or integer of the red component
1096 ...         $g  (int)       Integer of the green component
1097 ...         $b  (int)       Integer of the blue component
1098 ...     *}
1099 ... 
1100 ...     {*return
1101 ...         (array)     Resulting color as a CMY associative array[br]
1102 ...                         [c]c[/c]   … cyan value[br]
1103 ...                         [c]m[/c]   … magenta value[br]
1104 ...                         [c]y[/c]   … yellow value[br]
1105 ...     *}
1106 ... 
1107 ...     {*credits
1108 ...         Adapted from [url]http://www.easyrgb.com/math.php?MATH=M11#text11[/url].
1109 ...     *}
1110 ... 
1111 ...     {*exec
1112 ...         var_dump( COLOR_rgb2cmy( 100,150,200 ) );
1113 ...     *}
1114 ... 
1115 ...     *}}
1116 ...  */
1117 ... /* ========================================================================== */
1118 ... function COLOR_rgb2cmy( $r,$g = null,$b = null )
1119 ... /*---------------------------------------------*/
1120 ... {
1121 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
1122 ...     {
1123 ...         $g = $r['g'];                                               /* Green component */
1124 ...         $b = $r['b'];                                               /* Blue component */
1125 ...         $r = $r['r'];                                               /* Red component */
1126 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
1127 ... 
1128 ...     return ( array( 'c' => 1 - ( $r / 255 ),
1129 ...                     'm' => 1 - ( $g / 255 ),
1130 ...                     'y' => 1 - ( $b / 255 )
1131 ...                   ) );
1132 ... }   /* End of function COLOR_rgb2cmy() ====================================== */
1133 ... 
1134 ... /* ========================================================================== */
1135 ... /** {{*COLOR_cmy2rgb( $c[,$m[,$y]] )=
1136 ... 
1137 ...     Transforms a CMY color into its RGB equivalent
1138 ... 
1139 ...     {*params
1140 ...         $c  (mixed)     Array of CMY values or integer of the cyan component
1141 ...         $m  (int)       Integer of the magenta component
1142 ...         $y  (int)       Integer of the yellow component
1143 ...     *}
1144 ... 
1145 ...     {*return
1146 ...         (array)         The resulting color as a RGB associative array
1147 ...     *}
1148 ... 
1149 ...     {*credits
1150 ...         Adapted from [url]http://www.easyrgb.com/math.php?MATH=M11#text12[/url].
1151 ...     *}
1152 ... 
1153 ...     {*exec
1154 ...         $aCMY = array( 'c' => 0.6078431372549,
1155 ...                        'm' => 0.41176470588235,
1156 ...                        'y' => 0.2156862745098 );
1157 ...         var_dump( COLOR_cmy2rgb( $aCMY ) );
1158 ...     *}
1159 ... 
1160 ...     {*assert
1161 ...         COLOR_cmyk2rgb( $c,$m,$y,$k )
1162 ...     *}
1163 ... 
1164 ...     *}}
1165 ...  */
1166 ... /* ========================================================================== */
1167 ... function COLOR_cmy2rgb( $c,$m = null,$y = null )
1168 ... /*---------------------------------------------*/
1169 ... {
1170 ...     if ( is_array( $c ) && isset( $c['c'] ) )
1171 ...     {
1172 ...         $m = $c['m'];
1173 ...         $y = $c['y'];
1174 ...         $c = $c['c'];
1175 ...     }
1176 ... 
1177 ...     return ( array( 'r' => (int) ( ( 1 - $c ) * 255 ),
1178 ...                     'g' => (int) ( ( 1 - $m ) * 255 ),
1179 ...                     'b' => (int) ( ( 1 - $y ) * 255 )
1180 ...                   ) );
1181 ... }   /* End of function COLOR_cmy2rgb() ====================================== */
1182 ... 
1183 ... /* ========================================================================== */
1184 ... /** {{*COLOR_cmy2cmyk( $c[,$m[,$y]] )=
1185 ... 
1186 ...     Transforms a CMY associative array into a CMYK associative array
1187 ... 
1188 ...     {*params
1189 ...         $c  (mixed)     Array of CMY values or integer of the cyan component
1190 ...         $m  (int)       Integer of the magenta component
1191 ...         $y  (int)       Integer of the yellow component
1192 ...     *}
1193 ... 
1194 ...     {*return
1195 ...         (array)         Resulting color as a CMYK associative array[br]
1196 ...                             [c]c[/c]   … cyan value[br]
1197 ...                             [c]m[/c]   … magenta value[br]
1198 ...                             [c]y[/c]   … yellow value[br]
1199 ...                             [c]k[/c]   … black value[br]
1200 ...     *}
1201 ... 
1202 ...     {*credits
1203 ...         Adapted from [url]http://www.easyrgb.com/math.php?MATH=M13#text13[/url].
1204 ...     *}
1205 ... 
1206 ...     {*exec
1207 ...         var_dump( COLOR_cmy2cmyk( COLOR_rgb2cmy( 100,150,200 ) ) );
1208 ...     *}
1209 ... 
1210 ...     *}}
1211 ...  */
1212 ... /* ========================================================================== */
1213 ... function COLOR_cmy2cmyk( $c,$m = null,$y = null )
1214 ... /*---------------------------------------------*/
1215 ... {
1216 ...     if ( is_array( $c ) && isset( $c['c'] ) )                       /* If array passed */
1217 ...     {
1218 ...         $m = $c['m'];                                               /* Magenta component */
1219 ...         $y = $c['y'];                                               /* Yellow component */
1220 ...         $c = $c['c'];                                               /* Cyan component */
1221 ...     }   /* if ( is_array( $c ) && isset( $c['c'] ) ) */
1222 ... 
1223 ...     $k = 1;
1224 ... 
1225 ...     if ( $c < $k )   $k = $c;
1226 ...     if ( $m < $k )   $k = $m;
1227 ...     if ( $y < $k )   $k = $y;
1228 ... 
1229 ...     if ( $k == 1 )
1230 ...     {
1231 ...         $c = 0;
1232 ...         $m = 0;
1233 ...         $y = 0;
1234 ...     }
1235 ...     else
1236 ...     {
1237 ...         $c = ( $c - $k ) / ( 1 - $k );
1238 ...         $m = ( $m - $k ) / ( 1 - $k );
1239 ...         $y = ( $y - $k ) / ( 1 - $k );
1240 ...     }
1241 ... 
1242 ...     return ( array( 'c' => (float) $c,
1243 ...                     'm' => (float) $m,
1244 ...                     'y' => (float) $y,
1245 ...                     'k' => (float) $k
1246 ...                   ) );
1247 ... }   /* End of function COLOR_cmy2cmyk() ===================================== */
1248 ... 
1249 ... /* ========================================================================== */
1250 ... /** {{*COLOR_cmyk2cmy( $c[,$m[,$y[,$k]]] )=
1251 ... 
1252 ...     Transforms a CMYK associative array into a CMY associative array
1253 ... 
1254 ...     {*params
1255 ...         $c  (mixed)     Array of CMYK values or float of the cyan component
1256 ...         $m  (float)     Magenta component
1257 ...         $y  (float)     Yellow component
1258 ...         $k  (float)     Black component
1259 ...     *}
1260 ... 
1261 ...     {*return
1262 ...         (array)         Resulting color as a CMY associative array[br]
1263 ...                             [c]c[/c]   … cyan value[br]
1264 ...                             [c]m[/c]   … magenta value[br]
1265 ...                             [c]y[/c]   … yellow value[br]
1266 ...     *}
1267 ... 
1268 ...     {*credits
1269 ...         Adapted from [url]http://www.easyrgb.com/math.php?MATH=M14#text14[/url].
1270 ...     *}
1271 ... 
1272 ...     {*exec
1273 ...         var_dump( $aCMYK = COLOR_cmy2cmyk( COLOR_rgb2cmy( 100,150,200 ) ) );
1274 ...         var_dump( COLOR_cmyk2cmy( $aCMYK ) );
1275 ...     *}
1276 ... 
1277 ...     *}}
1278 ...  */
1279 ... /* ========================================================================== */
1280 ... function COLOR_cmyk2cmy( $c,$m = null,$y = null,$k = null )
1281 ... /*-------------------------------------------------------*/
1282 ... {
1283 ...     if ( is_array( $c ) && isset( $c['c'] ) )
1284 ...     {
1285 ...         $m = $c['m'];
1286 ...         $y = $c['y'];
1287 ...         $k = $c['k'];
1288 ...         $c = $c['c'];
1289 ...     }
1290 ... 
1291 ...     $c = ( $c * ( 1 - $k ) + $k );
1292 ...     $m = ( $m * ( 1 - $k ) + $k );
1293 ...     $y = ( $y * ( 1 - $k ) + $k );
1294 ... 
1295 ...     return ( array( 'c' => $c,
1296 ...                     'm' => $m,
1297 ...                     'y' => $y
1298 ...                   ) );
1299 ... }   /* End of function COLOR_cmyk2cmy() ===================================== */
1300 ... 
1301 ... /* ========================================================================== */
1302 ... /** {{*COLOR_rgb2cmyk( $r,$g,$b )= Turns a RGB color to its CMYK counterpart
1303 ... 
1304 ...     {*params
1305 ...         $r  (mixed)     Array of RGB colors or integer of the red component
1306 ...         $g  (int)       Integer of the green component. Optional if $r is an array.
1307 ...         $b  (int)       Integer of the blue component. Optional if $r is an array.
1308 ...     *}
1309 ... 
1310 ...     {*return
1311 ...         (array)     CMYK parts (associative array: 'c', 'm', 'y', 'k')
1312 ...     *}
1313 ... 
1314 ...     {*exec
1315 ...         var_dump( COLOR_rgb2cmyk( 255,128,255 ) );
1316 ...     *}
1317 ... 
1318 ...     {*exec
1319 ...         // array:  'c' => int 0, 'm' => float 0.49803921568627, 'y' => int 0, 'k' => int 0
1320 ...         var_dump( $aCMYK = COLOR_rgb2cmyk( 255,128,255 ) );
1321 ... 
1322 ...         echo LSUnitTesting::assert( $aCMYK['c'] === 0.0 &&
1323 ...                                     $aCMYK['m'] > 0.498 &&
1324 ...                                     $aCMYK['m'] < 0.5   &&
1325 ...                                     $aCMYK['y'] === 0.0 &&
1326 ...                                     $aCMYK['k'] === 0.0                 ,
1327 ...                                     'ASSERTION SUCCESS: cmyk correct'   ,
1328 ...                                     'ASSERTION SUCCESS: cmyk incorrect' ,
1329 ...                                     'GuideAssert' );
1330 ... 
1331 ...         var_dump( $aCMYK = COLOR_rgb2cmyk( 245,134,52 ) );
1332 ... 
1333 ...         echo LSUnitTesting::assert( $aCMYK['c'] === 0.0     &&
1334 ...                                     $aCMYK['m'] > 0.453     &&
1335 ...                                     $aCMYK['m'] < 0.454     &&
1336 ...                                     $aCMYK['y'] > 0.787     &&
1337 ...                                     $aCMYK['y'] < 0.788     &&
1338 ...                                     $aCMYK['k'] > 0.039     &&
1339 ...                                     $aCMYK['k'] < 0.040                 ,
1340 ...                                     'ASSERTION SUCCESS: cmyk correct'   ,
1341 ...                                     'ASSERTION SUCCESS: cmyk incorrect' ,
1342 ...                                     'GuideAssert' );
1343 ...     *}
1344 ... 
1345 ...     {*seealso
1346 ...         COLOR_rgb2hex(), COLOR_cmyk2rgb()
1347 ...     *}
1348 ... 
1349 ...     *}}
1350 ...  */
1351 ... /* ========================================================================== */
1352 ... function COLOR_rgb2cmyk( $r,$g = null,$b = null )
1353 ... /*---------------------------------------------*/
1354 ... {
1355 ...     if ( is_array( $r ) && isset( $r['r'] ) )                       /* If array passed */
1356 ...     {
1357 ...         $g = $r['g'];                                               /* Green component */
1358 ...         $b = $r['b'];                                               /* Blue component */
1359 ...         $r = $r['r'];                                               /* Red component */
1360 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
1361 ... 
1362 ...     return( COLOR_cmy2cmyk( COLOR_rgb2cmy( $r,$g,$b ) ) );          /* Return value of the function */
1363 ... 
1364 ... }   /* End of function COLOR_rgb2cmyk() ===================================== */
1365 ... 
1366 ... /* ========================================================================== */
1367 ... /** {{*COLOR_cmyk2rgb( $c[,$m,$y,$k] )=
1368 ... 
1369 ...     Turns a CMYK color int to its RGB counterpart
1370 ... 
1371 ...     {*params
1372 ...         $c  (mixed)     Array of CMYK values or float of the cyan component
1373 ...         $m  (float)     Magenta component if $c is not a CMYK array
1374 ...         $y  (float)     Yellow component if $c is not a CMYK array
1375 ...         $k  (float)     Black component if $c is not a CMYK array
1376 ...     *}
1377 ... 
1378 ...     {*return
1379 ...         (array)     Resulting color as a RGB associative array[br]
1380 ...                         [c]r[/c]   … red value[br]
1381 ...                         [c]g[/c]   … green value[br]
1382 ...                         [c]b[/c]   … blue value[br]
1383 ...     *}
1384 ... 
1385 ...     {*exec
1386 ...         var_dump( $aCMYK = COLOR_rgb2cmyk( 255,128,255 ) );
1387 ...         var_dump( $aRGB = COLOR_cmyk2rgb( $aCMYK ) );
1388 ... 
1389 ...         echo LSUnitTesting::assert( $aRGB['r'] == 255   &&
1390 ...                                     $aRGB['g'] == 128   &&
1391 ...                                     $aRGB['b'] == 255                                       ,
1392 ...                                     'ASSERTION SUCCESS: rgb correct (get back to original)' ,
1393 ...                                     'ASSERTION SUCCESS: rgb incorrect'                      ,
1394 ...                                     'GuideAssert' );
1395 ...         $aRGB = COLOR_cmyk2rgb( 0,0.498,0.749,0 );
1396 ...     *}
1397 ... 
1398 ...     {*assert
1399 ...         COLOR_cmyk2rgb( 0,0.498,0.749,0 ) === array( 'r' => 255,'g' => 128,'b' => 64 )
1400 ...     *}
1401 ... 
1402 ...     {*seealso
1403 ...         COLOR_rgb2cmyk()
1404 ...     *}
1405 ... 
1406 ...     *}}
1407 ...  */
1408 ... /* ========================================================================== */
1409 ... function COLOR_cmyk2rgb( $c,$m = null,$y = null,$k = null )
1410 ... /*-------------------------------------------------------*/
1411 ... {
1412 ...     if ( is_array( $c ) && isset( $c['c'] ) )                       /* If array passed */
1413 ...     {
1414 ...         $m = $c['m'];                                               /* Magenta component */
1415 ...         $y = $c['y'];                                               /* Yellow component */
1416 ...         $k = $c['k'];                                               /* Black component */
1417 ...         $c = $c['c'];                                               /* Cyan component */
1418 ...     }   /* if ( is_array( $c ) && isset( $c['c'] ) ) */
1419 ... 
1420 ...     return ( COLOR_cmy2rgb( COLOR_cmyk2cmy( $c,$m,$y,$k ) ) );      /* Transform the CMYK to a CMY value, then transform the CMY value to a RGB value : return the result */
1421 ... }   /* End of function COLOR_cmyk2rgb() ===================================== */
1422 ... 
1423 ... /* ========================================================================== */
1424 ... /*
1425 ...     http://homepages.cwi.nl/~steven/css/hsl.html
1426 ... 
1427 ...     The algorithm to translate HSL to RGB is simple
1428 ...     In these algorithms, all three values (H, S and L) have
1429 ...     been normalised to fractions 0..1:
1430 ...     HOW TO RETURN hsl.to.rgb(h, s, l):
1431 ...        SELECT:
1432 ... 	  l<=0.5: PUT l*(s+1) IN m2
1433 ... 	  ELSE: PUT l+s-l*s IN m2
1434 ...        PUT l*2-m2 IN m1
1435 ...        PUT hue.to.rgb(m1, m2, h+1/3) IN r
1436 ...        PUT hue.to.rgb(m1, m2, h    ) IN g
1437 ...        PUT hue.to.rgb(m1, m2, h-1/3) IN b
1438 ...        RETURN (r, g, b)
1439 ... 
1440 ...     HOW TO RETURN hue.to.rgb(m1, m2, h):
1441 ...        IF h<0: PUT h+1 IN h
1442 ...        IF h>1: PUT h-1 IN h
1443 ...        IF h*6<1: RETURN m1+(m2-m1)*h*6
1444 ...        IF h*2<1: RETURN m2
1445 ...        IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
1446 ...        RETURN m1
1447 ... */
1448 ... 
1449 ... /* ========================================================================== */
1450 ... /** {{*COLOR_rgb2hsl( $r,$g,$b )=
1451 ... 
1452 ...     Turns a RGB color to its HSL constituents
1453 ... 
1454 ...     {*params
1455 ...         $r  (mixed)     Array of RGB colors or integer of the red component
1456 ...         $g  (int)       Integer of the green component if $r is an integer
1457 ...         $b  (int)       Integer of the blue component if $r is an integer
1458 ...     *}
1459 ... 
1460 ...     {*return
1461 ...         (array)         Resulting color as a RGB associative array[br]
1462 ...                         [c]'h'[/c] ... hue value[br]
1463 ...                         [c]'s'[/c] ... saturation value[br]
1464 ...                         [c]'l'[/c] ... luminosity value
1465 ...     *}
1466 ... 
1467 ...     {*exec
1468 ...         var_dump( $aHSL= COLOR_rgb2hsl( 255,128,255 ) );
1469 ...     *}
1470 ... 
1471 ...     *}}
1472 ...  */
1473 ... /* ========================================================================== */
1474 ... function COLOR_rgb2hsl( $r,$g = null,$b = null )
1475 ... /*--------------------------------------------*/
1476 ... {
1477 ...     if ( is_array( $r ) && isset( $r['r'] ) )                   /* If array passed */
1478 ...     {
1479 ...         $g = $r['g'];                                           /* Green component */
1480 ...         $b = $r['b'];                                           /* Blue component */
1481 ...         $r = $r['r'];                                           /* Red component */
1482 ...     }   /* if ( is_array( $r ) && isset( $r['r'] ) ) */
1483 ... 
1484 ...     $r /= 255;                                                  /* Let's first divide red into percentage */
1485 ...     $g /= 255;                                                  /* Let's first divide green into percentage */
1486 ...     $b /= 255;                                                  /* Let's first divide blue into percentage */
1487 ... 
1488 ...     $iMin   = min( $r,$g,$b );                                  /* What's the minimum of all three pigments */
1489 ...     $iMax   = max( $r,$g,$b );                                  /* What's the maximum of all three pigments */
1490 ... 
1491 ...     $delta  = $iMax - $iMin;                                    /* Calculate delta */
1492 ... 
1493 ...     $h = $s = $l = 0;                                           /* Store default values (starting from black) */
1494 ... 
1495 ...     $l = ( $iMax + $iMin ) / 2;
1496 ... 
1497 ...     if ( $l > 0 )
1498 ...     {
1499 ...         $delta = $iMax - $iMin;
1500 ... 
1501 ...         $s = $delta;
1502 ... 
1503 ...         if ( $s > 0 )
1504 ...         {
1505 ...             $s /= ( $l <= 0.5 ) ? ( $iMax + $iMin ) : ( 2 - $iMax - $iMin );
1506 ... 
1507 ...             $r2 = ( $iMax - $r ) / $delta;
1508 ...             $g2 = ( $iMax - $g ) / $delta;
1509 ...             $b2 = ( $iMax - $b ) / $delta;
1510 ... 
1511 ...             if      ( $r == $iMax )
1512 ...             {
1513 ...                 $h = ( $g == $iMin ? 5 + $b2 : 1 - $g2 );
1514 ...             }
1515 ...             else if ( $g == $iMax )
1516 ...             {
1517 ...                 $h = ( $b == $iMin ? 1 + $r2 : 3 - $b2 );
1518 ...             }
1519 ...             else
1520 ...             {
1521 ...                 $h = ( $r == $iMin ? 3 + $g2 : 5 - $r2 );
1522 ...             }
1523 ... 
1524 ...             $h /= 6;
1525 ...         }
1526 ...     }
1527 ... 
1528 ...     if ( $h < 0 )
1529 ...     {
1530 ...         $h += 1;
1531 ...     }
1532 ... 
1533 ...     if ( $h > 1 )
1534 ...     {
1535 ...         $h -= 1;
1536 ...     }
1537 ... 
1538 ...     return ( array( 'h' => (float) round( $h,5 ),
1539 ...                     's' => (float) round( $s,5 ),
1540 ...                     'l' => (float) round( $l,5 )
1541 ...                   ) );
1542 ... }   /* End of function COLOR_rgb2hsl() ====================================== */
1543 ... 
1544 ... /* ========================================================================== */
1545 ... function COLOR_hsl2rgb( $h,$s = null,$l = null )
1546 ... /*--------------------------------------------*/
1547 ... {
1548 ...     if ( is_array( $h ) && isset( $h['h'] ) )
1549 ...     {
1550 ...         $s = $h['s'];
1551 ...         $l = $h['l'];
1552 ...         $h = $h['h'];
1553 ...     }
1554 ... 
1555 ...     if ( $s == 0 )
1556 ...     {
1557 ...         $r = $l * 255;
1558 ...         $g = $l * 255;
1559 ...         $b = $l * 255;
1560 ...     }
1561 ...     else
1562 ...     {
1563 ...         if ( $l < 0.5 )
1564 ...         {
1565 ...             $var_2 = $l * ( 1 + $s );
1566 ...         }
1567 ...         else
1568 ...         {
1569 ...             $var_2 = ($l + $s) - ($s * $l);
1570 ...         }
1571 ... 
1572 ...         $var_1 = 2 * $l - $var_2;
1573 ...         $r     = 255 * hue_2_rgb( $var_1,$var_2,$h + (1 / 3) );
1574 ...         $g     = 255 * hue_2_rgb( $var_1,$var_2,$h           );
1575 ...         $b     = 255 * hue_2_rgb( $var_1,$var_2,$h - (1 / 3) );
1576 ...     }
1577 ... 
1578 ...     return ( array( 'r' => round( $r ),
1579 ...                     'g' => round( $g ),
1580 ...                     'b' => round( $b )
1581 ...                   ) );
1582 ... }   /* End of function COLOR_hsl2rgb() ====================================== */
1583 ... 
1584 ... /* ========================================================================== */
1585 ... function hue_2_rgb( $v1,$v2,$vh )
1586 ... /*-----------------------------*/
1587 ... {
1588 ...     if ( $vh < 0 )
1589 ...     {
1590 ...         $vh += 1;
1591 ...     }
1592 ... 
1593 ...     if ( $vh > 1 )
1594 ...     {
1595 ...         $vh -= 1;
1596 ...     }
1597 ... 
1598 ...     if ( ( 6 * $vh ) < 1 )
1599 ...     {
1600 ...         return ($v1 + ( $v2 - $v1 ) * 6 * $vh );
1601 ...     }
1602 ... 
1603 ...     if ( ( 2 * $vh ) < 1 )
1604 ...     {
1605 ...         return ( $v2 );
1606 ...     }
1607 ... 
1608 ...     if ( ( 3 * $vh ) < 2 )
1609 ...     {
1610 ...         return ( $v1 + ( $v2 - $v1 ) * ( (2 / 3 - $vh ) * 6 ) );
1611 ...     }
1612 ... 
1613 ...     return ( $v1 );
1614 ... }   /* End of function hue_2_rgb() ========================================== */
1615 ... 

Manifest Constants

LS_COLOR_FUNCTIONS_PWH: Remember that THESE functions have been declared

VAESOLI_PATH: Define the path where Vae Soli! is installed

VAESOLI_PLUGINS: Define the path where plugins are located

UltraEdit Syntax files

  1. UltraEdit keywords of LSColors.functions.php
  2. UltraEdit Syntax of LSColors.functions.php

Function List (TOC)

  1. COLOR_Blend(): Returns an array of intermediate color values between 2 colors
  2. COLOR_cmy2cmyk(): Transforms a CMY associative array into a CMYK associative array No assertion found for COLOR_cmy2cmyk() (0 - 0)
  3. COLOR_cmy2rgb(): Transforms a CMY color into its RGB equivalent
  4. COLOR_cmyk2cmy(): Transforms a CMYK associative array into a CMY associative array No assertion found for COLOR_cmyk2cmy() (0 - 0)
  5. COLOR_cmyk2rgb(): Turns a CMYK color int to its RGB counterpart
  6. COLOR_Complementary(): Finds the complementary color of a given color
  7. COLOR_Component(): Returns the most important hue component (red,green or blue) of a given color
  8. COLOR_Contrast(): Contrast ratio between 2 colors
  9. COLOR_hex2rgb(): Turns a hex color into RGB parts
  10. COLOR_hsv2rgb(): Turns a HSV value into its RGB equivalent No assertion found for COLOR_hsv2rgb() (0 - 0)
  11. COLOR_hue(): Returns the hue of a given color
  12. COLOR_int2rgb(): Turns an integer into a RGB color
  13. COLOR_KelvinToRGB(): Returns RGB value corresponding to a given temperature
  14. COLOR_Luminosity(): Returns color luminosity
  15. COLOR_nadir(): Returns the color right at the opposite of rgb( $r,$g,$b )
  16. COLOR_rgb2cmy(): Transforms a color into a CMY associative array No assertion found for COLOR_rgb2cmy() (0 - 0)
  17. COLOR_rgb2cmyk(): Turns a RGB color to its CMYK counterpart
  18. COLOR_rgb2gray(): Transforms a color into a grey flavor
  19. COLOR_rgb2hex(): Turns a RGB color to its HTML hexa counterpart
  20. COLOR_rgb2hsl(): Turns a RGB color to its HSL constituents No assertion found for COLOR_rgb2hsl() (0 - 0)
  21. COLOR_rgb2hsv(): Turns an RGB color into hue, saturation and value No assertion found for COLOR_rgb2hsv() (0 - 0)
  22. COLOR_rgb2int(): Turns an RGB color into an integer

Functions of LSColors.functions.php

COLOR_Blend(): Returns an array of intermediate color values between 2 colors

[ back to function list ]

Syntax

COLOR_Blend( $rgb1,$rgb2,$iSteps )

Parameters
NameTypeDescription
$rgb1 array Array of RGB colors (start value)
$rgb2 array Array of RGB colors (end value)
$iSteps int Number of steps between start and end
Return

(array) Array of arrays (RGB colors)

Example Executed
echo "This example generates the nice gradient below:\n\n";

$szTag    = 'span';
$szPStyle = "display:inline-block;width:300px;background";

$aRgb1 = array( 'r' => 255,'g' =>   0,'b' => 0 );
$aRgb2 = array( 'r' => 255,'g' => 255,'b' => 0 );

$aRgbs  = COLOR_blend( $aRgb1,$aRgb2,20 );
$szRGBs = serialize( $aRgbs );
$szHTML = '';

foreach( $aRgbs as $aRgb )
{
    echo $szColorStrip = "<{$szTag} style=\"{$szPStyle}:rgb({$aRgb['r']},{$aRgb['g']},{$aRgb['b']});\">&#160;</{$szTag}>\n";
    $szHTML .= $szColorStrip;
}

echo LSUnitTesting::assert( $aRgbs[7]['r'] === 255  &&
                            $aRgbs[7]['g'] === 89   &&
                            $aRgbs[7]['b'] === 0    &&
                            count( $aRgbs ) === 21                          ,
                            'ASSERTION SUCCESS: Gotcha!'                    ,
                            'ASSERTION FAILURE: Houston, we have a problem!',
                            'GuideAssert' );

This example generates the nice gradient below:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

GuideAssert() ... ASSERTION SUCCESS: Gotcha!

Unit Testing

1 assertions: 1 successful; 0 failed

COLOR_cmy2cmyk(): Transforms a CMY associative array into a CMYK associative array

[ back to function list ]

Credits

Adapted from .

Syntax

COLOR_cmy2cmyk( $c,$m,$y )

Parameters
NameTypeDescription
$c mixed Array of CMY values or integer of the cyan component
$m int Integer of the magenta component
$y int Integer of the yellow component
Return

(array) Resulting color as a CMYK associative array
c … cyan value
m … magenta value
y … yellow value
k … black value

Example Executed
var_dump( COLOR_cmy2cmyk( COLOR_rgb2cmy( 100,150,200 ) ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=4)
  'c' => float 0.5
  'm' => float 0.25
  'y' => float 0
  'k' => float 0.2156862745098
Unit Testing

WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}) or with GuideAssert() function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}).

COLOR_cmy2rgb(): Transforms a CMY color into its RGB equivalent

[ back to function list ]

Credits

Adapted from .

Syntax

COLOR_cmy2rgb( $c,$m,$y )

Parameters
NameTypeDescription
$c mixed Array of CMY values or integer of the cyan component
$m int Integer of the magenta component
$y int Integer of the yellow component
Return

(array) The resulting color as a RGB associative array

Example Executed
$aCMY = array( 'c' => 0.6078431372549,
               'm' => 0.41176470588235,
               'y' => 0.2156862745098 );
var_dump( COLOR_cmy2rgb( $aCMY ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:4:
array (size=3)
  'r' => int 100
  'g' => int 150
  'b' => int 200
Assertions

COLOR_cmyk2rgb( $c,$m,$y,$k ) successful

Unit Testing

1 assertions: 1 successful; 0 failed

COLOR_cmyk2cmy(): Transforms a CMYK associative array into a CMY associative array

[ back to function list ]

Credits

Adapted from .

Syntax

COLOR_cmyk2cmy( $c,$m,$y,$k )

Parameters
NameTypeDescription
$c mixed Array of CMYK values or float of the cyan component
$m float Magenta component
$y float Yellow component
$k float Black component
Parameters Warning

COLOR_cmyk2cmy() uses 4 parameters whereas the suggested limit is 3.

Return

(array) Resulting color as a CMY associative array
c … cyan value
m … magenta value
y … yellow value

Example Executed
var_dump( $aCMYK = COLOR_cmy2cmyk( COLOR_rgb2cmy( 100,150,200 ) ) );
var_dump( COLOR_cmyk2cmy( $aCMYK ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=4)
  'c' => float 0.5
  'm' => float 0.25
  'y' => float 0
  'k' => float 0.2156862745098
D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:2:
array (size=3)
  'c' => float 0.6078431372549
  'm' => float 0.41176470588235
  'y' => float 0.2156862745098
Unit Testing

WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}) or with GuideAssert() function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}).

COLOR_cmyk2rgb(): Turns a CMYK color int to its RGB counterpart

[ back to function list ]

Syntax

COLOR_cmyk2rgb( $c,$m,$y,$k )

Parameters
NameTypeDescription
$c mixed Array of CMYK values or float of the cyan component
$m float Magenta component if $c is not a CMYK array
$y float Yellow component if $c is not a CMYK array
$k float Black component if $c is not a CMYK array
Parameters Warning

COLOR_cmyk2rgb() uses 4 parameters whereas the suggested limit is 3.

Return

(array) Resulting color as a RGB associative array
r … red value
g … green value
b … blue value

Example Executed
var_dump( $aCMYK = COLOR_rgb2cmyk( 255,128,255 ) );
var_dump( $aRGB = COLOR_cmyk2rgb( $aCMYK ) );

echo LSUnitTesting::assert( $aRGB['r'] == 255   &&
                            $aRGB['g'] == 128   &&
                            $aRGB['b'] == 255                                       ,
                            'ASSERTION SUCCESS: rgb correct (get back to original)' ,
                            'ASSERTION SUCCESS: rgb incorrect'                      ,
                            'GuideAssert' );
$aRGB = COLOR_cmyk2rgb( 0,0.498,0.749,0 );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=4)
  'c' => float 0
  'm' => float 0.49803921568627
  'y' => float 0
  'k' => float 0
D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:2:
array (size=3)
  'r' => int 255
  'g' => int 128
  'b' => int 255

GuideAssert() ... ASSERTION SUCCESS: rgb correct (get back to original)

Assertions

COLOR_cmyk2rgb( 0,0.498,0.749,0 ) === array( 'r' => 255,'g' => 128,'b' => 64 ) successful

Unit Testing

2 assertions: 2 successful; 0 failed

See Also

COLOR_rgb2cmyk()

COLOR_Complementary(): Finds the complementary color of a given color

[ back to function list ]

Credits

Adapted from .

Syntax

COLOR_Complementary( $r,$g,$b,$degree )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component (if $r NOT array)
$b int Integer of the blue component (if $r NOT array)
$degree int Complementary color based on a given hue degree. Optional. 180° by default (nadir)
Parameters Warning

COLOR_Complementary() uses 4 parameters whereas the suggested limit is 3.

Return

(array) Resulting color as a RGB associative array
r … red value
g … green value
b … blue value

Example Executed
var_dump( $aRGB = COLOR_Complementary( 100,150,200 ) );

echo LSUnitTesting::assert( $aRGB['r'] == 200 &&
                            $aRGB['g'] == 150 &&
                            $aRGB['b'] == 100                                               ,
                            'ASSERTION SUCCESS: complementary color successfully calculated',
                            'ASSERTION FAILURE: unexpected complementary color'             ,
                            'GuideAssert' );

var_dump( $aRGB = COLOR_Complementary( $aRGB ) );

echo LSUnitTesting::assert( $aRGB['r'] == 100 &&
                            $aRGB['g'] == 150 &&
                            $aRGB['b'] == 200                                   ,
                            'ASSERTION SUCCESS: return to original on 180&deg;' ,
                            'ASSERTION FAILURE: unexpected complementary color' ,
                            'GuideAssert' );

var_dump( $aRGB = COLOR_Complementary( $aRGB,null,null,100 ) );

echo LSUnitTesting::assert( $aRGB['r'] == 200 &&
                            $aRGB['g'] == 100 &&
                            $aRGB['b'] == 183                                   ,
                            'ASSERTION SUCCESS: complementary on 100&deg;'      ,
                            'ASSERTION FAILURE: unexpected complementary color' ,
                            'GuideAssert' );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=3)
  'r' => float 200
  'g' => float 150
  'b' => float 100

GuideAssert() ... ASSERTION SUCCESS: complementary color successfully calculated

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:10:
array (size=3)
  'r' => float 100
  'g' => float 150
  'b' => float 200

GuideAssert() ... ASSERTION SUCCESS: return to original on 180°

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:19:
array (size=3)
  'r' => float 200
  'g' => float 100
  'b' => float 183

GuideAssert() ... ASSERTION SUCCESS: complementary on 100°

Unit Testing

3 assertions: 3 successful; 0 failed

COLOR_Component(): Returns the most important hue component (red,green or blue) of a given color

[ back to function list ]

Caution

In the case the tints are equal, red has precedence over green and blue, and green has precedence over blue

Syntax

COLOR_Component( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component. Optional if $r is an array.
$b int Integer of the blue component. Optional if $r is an array.
Return

(char) Letter indicating the most important tint: 'r', or 'g', or 'b'

Example(s)
COLOR_Component( 255,128,255 ) -> "r"
COLOR_Component( 128,255,255 ) -> "g"
COLOR_Component( 255,255,255 ) -> "r"
COLOR_Component( 1,2,3 )       -> "b"
Assertions

COLOR_Component( 255,128,255 ) === "r" successful

COLOR_Component( 128,255,255 ) === "g" successful

COLOR_Component( 255,255,255 ) === "r" successful

COLOR_Component( 1,2,3 ) === "b" successful

COLOR_Component( array( 'r' => 1,'g' => 2,'b' => 3 ) ) === "b" successful

Unit Testing

5 assertions: 5 successful; 0 failed

COLOR_Contrast(): Contrast ratio between 2 colors

[ back to function list ]

Created: 19/05/2013 19:30

Since version 5.3.0002

Author

Docs

The highest contrast is 21; the lowest is 1. A contrast of 5 gives a AA level; a contrast of 7 gives a AAA grade. See Web Content Accessibility Guidelines 2.0:

Syntax

COLOR_Contrast( $aRGB_A,$aRGB_B )

Parameters
NameTypeDescription
$aRGB_A array RGB associative array
r ... red value
g ... green value
b ... blue value
$aRGB_B array RGB associative array
r ... red value
g ... green value
b ... blue value
Return

(float) Contrast ratio

Examples Executed
Example #1
echo COLOR_Contrast( array( 'r' => 255,'g' => 255,'b' => 255 ),array( 'r' => 0,'g' => 0,'b' => 0 ) );

21
Example #2
echo COLOR_Contrast( array( 'r' => 255,'g' => 255,'b' => 255 ),array( 'r' => 255,'g' => 255,'b' => 255 ) );

1
Assertions

COLOR_Contrast( array( 'r' => 255,'g' => 255,'b' => 255 ),array( 'r' => 0,'g' => 0,'b' => 0 ) ) === (float) 21 successful

COLOR_Contrast( array( 'r' => 255,'g' => 0,'b' => 0 ),array( 'r' => 0,'g' => 0,'b' => 0 ) ) === 5.252 successful

Unit Testing

2 assertions: 2 successful; 0 failed

COLOR_hex2rgb(): Turns a hex color into RGB parts

[ back to function list ]

Syntax

COLOR_hex2rgb( $h )

Parameters
NameTypeDescription
$h string Hexadecimal color (e.g. #ffffff)
Return

(array) RGB associative array
r … red value
g … green value
b … blue value

Example Executed
var_dump( $aRGB = COLOR_hex2rgb( '#ff80ff' ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=3)
  'r' => int 255
  'g' => int 128
  'b' => int 255
Assertions

COLOR_hex2rgb( '#000000' ) === array( 'r' => 0,'g' => 0,'b' => 0 ) successful

COLOR_hex2rgb( '#ffffff' ) === array( 'r' => 255,'g' => 255,'b' => 255 ) successful

COLOR_hex2rgb( '#405060' ) === array( 'r' => 64,'g' => 80,'b' => 96 ) successful

Unit Testing

3 assertions: 3 successful; 0 failed

See Also

COLOR_rgb2hsl(), COLOR_int2rgb()

COLOR_hsv2rgb(): Turns a HSV value into its RGB equivalent

[ back to function list ]

Credits

Adapted from .

Syntax

COLOR_hsv2rgb( $h,$s,$v )

Alias

COLOR_hsb2rgb()

Parameters
NameTypeDescription
$h mixed Associative array (h,s,v) or int. If int, $h is the hue value
$s int Saturation value. Used if $h is an int.
$v int value. Used if $h is an int.
Return

(int) The resulting color as an RGB associative array

Unit Testing

WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}) or with GuideAssert() function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}).

COLOR_hue(): Returns the hue of a given color

[ back to function list ]

Syntax

COLOR_hue( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component
$b int Integer of the blue component
Return

(int) The resulting hue

Example Executed
echo "<p>",$i1 = COLOR_hue( 255,0,0 ),"</p>";
echo "<p>",$i2 = COLOR_hue( 255,255,0 ),"</p>";
echo "<p>",$i3 = COLOR_hue( 0,255,0 ),"</p>";
echo "<p>",$i4 = COLOR_hue( 0,255,255 ),"</p>";
echo "<p>",$i5 = COLOR_hue( 0,0,255 ),"</p>";
echo "<p>",$i6 = COLOR_hue( 255,0,255 ),"</p>";
echo "<p>",$i7 = COLOR_hue( 0,0,0 ),"</p>";
echo "<p>",$i8 = COLOR_hue( 255,255,255 ),"</p>";

echo LSUnitTesting::assert( $i1 === 0,
                            'ASSERTION SUCCESSFUL: hue #1 correct',
                            'ASSERTION SUCCESSFUL: hue #1 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i2 === 60,
                            'ASSERTION SUCCESSFUL: hue #2 correct',
                            'ASSERTION SUCCESSFUL: hue #2 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i3 === 120,
                            'ASSERTION SUCCESSFUL: hue #3 correct',
                            'ASSERTION SUCCESSFUL: hue #3 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i4 === 180,
                            'ASSERTION SUCCESSFUL: hue #4 correct',
                            'ASSERTION SUCCESSFUL: hue #4 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i5 === 240,
                            'ASSERTION SUCCESSFUL: hue #5 correct',
                            'ASSERTION SUCCESSFUL: hue #5 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i6 === 300,
                            'ASSERTION SUCCESSFUL: hue #6 correct',
                            'ASSERTION SUCCESSFUL: hue #6 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i7 === -1,
                            'ASSERTION SUCCESSFUL: hue #7 correct',
                            'ASSERTION SUCCESSFUL: hue #7 incorrect',
                            'GuideAssert' );
echo LSUnitTesting::assert( $i8 === -1,
                            'ASSERTION SUCCESSFUL: hue #8 correct',
                            'ASSERTION SUCCESSFUL: hue #8 incorrect',
                            'GuideAssert' );


0

60

120

180

240

300

-1

-1

GuideAssert() ... ASSERTION SUCCESSFUL: hue #1 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #2 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #3 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #4 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #5 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #6 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #7 correct

GuideAssert() ... ASSERTION SUCCESSFUL: hue #8 correct

Unit Testing

8 assertions: 8 successful; 0 failed

COLOR_int2rgb(): Turns an integer into a RGB color

[ back to function list ]

Syntax

COLOR_int2rgb( $x )

Parameters
NameTypeDescription
$x int Integer that must be turned to a RGB color
Return

(array) An associative array : 'r', 'g', 'b'

Example(s)
$iColor = COLOR_rgb2int( array( 'r' => 255,'g' => 160,'b' => 120 ) );
Assertions

COLOR_int2rgb( 7905535 ) === array( 'r' => 255,'g' => 160,'b' => 120 ) successful

COLOR_int2rgb( 15767160 ) === array( 'r' => 120,'g' => 150,'b' => 240 ) successful

Unit Testing

2 assertions: 2 successful; 0 failed

See Also

COLOR_rgb2int()

COLOR_KelvinToRGB(): Returns RGB value corresponding to a given temperature

[ back to function list ]

Credits

Syntax

COLOR_KelvinToRGB( $r,$g,$b,$k )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component if $r not array
$b int Integer of the blue component if $r not array
$k int Temperature in Kelvin
Parameters Warning

COLOR_KelvinToRGB() uses 4 parameters whereas the suggested limit is 3.

Return

(int) Luminosity (value between 0 (dark) and 1 (max lumininosity)

Example(s)
Example #1
echo COLOR_Luminosity( 255,128,255 );   // Prints 0.75098039215686

Example #2
echo COLOR_Luminosity( 160,120,255 );   // Prints 0.73529411764706
Assertions

round( COLOR_Luminosity( 255,128,255 ),3 ) === 0.751 successful

Unit Testing

1 assertions: 1 successful; 0 failed

COLOR_Luminosity(): Returns color luminosity

[ back to function list ]

Syntax

COLOR_Luminosity( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component
$b int Integer of the blue component
Return

(int) Luminosity (value between 0 (dark) and 1 (max lumininosity)

Example(s)
Example #1
echo COLOR_Luminosity( 255,128,255 );   // Prints 0.75098039215686

Example #2
echo COLOR_Luminosity( 160,120,255 );   // Prints 0.73529411764706
Assertions

round( COLOR_Luminosity( 255,128,255 ),3 ) === 0.751 successful

round( COLOR_Luminosity( 255,0,255 ),3 ) === 0.5 successful

round( COLOR_Luminosity( 200,200,200 ),3 ) === 0.784 successful

round( COLOR_Luminosity( 0,0,255 ),3 ) === 0.5 successful

Unit Testing

4 assertions: 4 successful; 0 failed

COLOR_nadir(): Returns the color right at the opposite of rgb( $r,$g,$b )

[ back to function list ]

Syntax

COLOR_nadir( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component
$b int Integer of the blue component
Return

(array) RGB associative array
r … red value
g … green value
b … blue value

Example Executed
$szStyle = 'text-align:center;font-size:2em;height:3em;line-height:3em;font-weight:bold;color:#000';

$aColor1 = array( 'r' => 100,'g' => 150,'b' => 200 );
$iColor1 = COLOR_rgb2int( $aColor1 );
$szHex01 = COLOR_rgb2hex( $aColor1 );

$aColor2 = COLOR_nadir( $aColor1 );
$iColor2 = COLOR_rgb2int( $aColor2 );
$szHex02 = COLOR_rgb2hex( $aColor2 );

echo "<p style=\"{$szStyle};background-color:{$szHex01}\">Color: {$szHex01} ($iColor1)</p>";
echo "<p style=\"{$szStyle};background-color:{$szHex02}\">Nadir: {$szHex02} ($iColor2)</p>";

var_dump( $aNadir = COLOR_nadir( 120,100,55 ) );

echo LSUnitTesting::assert( $iColor1 === 13145700,
                            'ASSERTION SUCCESSFUL: rgb2int correct on color #1',
                            'ASSERTION SUCCESSFUL: rgb2int incorrect on color #1',
                            'GuideAssert' );
echo LSUnitTesting::assert( $iColor2 === 3631515,
                            'ASSERTION SUCCESSFUL: rgb2int correct on color #2',
                            'ASSERTION SUCCESSFUL: rgb2int incorrect on color #2',
                            'GuideAssert' );
echo LSUnitTesting::assert( $szHex01 === '#6496c8',
                            'ASSERTION SUCCESSFUL: rgb2hex correct on color #1',
                            'ASSERTION SUCCESSFUL: rgb2hex correct on color #1',
                            'GuideAssert' );
echo LSUnitTesting::assert( $szHex02 === '#9b6937',
                            'ASSERTION SUCCESSFUL: rgb2hex correct on color #2',
                            'ASSERTION SUCCESSFUL: rgb2hex correct on color #2',
                            'GuideAssert' );
echo LSUnitTesting::assert( $aNadir['r'] === 135 && $aNadir['g'] === 155 && $aNadir['b'] === 200,
                            'ASSERTION SUCCESSFUL: nadir correct',
                            'ASSERTION SUCCESSFUL: nadir incorrect',
                            'GuideAssert' );

Color: #6496c8 (13145700)

Nadir: #9b6937 (3631515)

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:14:
array (size=3)
  'r' => int 135
  'g' => int 155
  'b' => int 200

GuideAssert() ... ASSERTION SUCCESSFUL: rgb2int correct on color #1

GuideAssert() ... ASSERTION SUCCESSFUL: rgb2int correct on color #2

GuideAssert() ... ASSERTION SUCCESSFUL: rgb2hex correct on color #1

GuideAssert() ... ASSERTION SUCCESSFUL: rgb2hex correct on color #2

GuideAssert() ... ASSERTION SUCCESSFUL: nadir correct

Unit Testing

5 assertions: 5 successful; 0 failed

COLOR_rgb2cmy(): Transforms a color into a CMY associative array

[ back to function list ]

Credits

Adapted from .

Syntax

COLOR_rgb2cmy( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component
$b int Integer of the blue component
Return

(array) Resulting color as a CMY associative array
c … cyan value
m … magenta value
y … yellow value

Example Executed
var_dump( COLOR_rgb2cmy( 100,150,200 ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=3)
  'c' => float 0.6078431372549
  'm' => float 0.41176470588235
  'y' => float 0.2156862745098
Unit Testing

WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}) or with GuideAssert() function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}).

COLOR_rgb2cmyk(): Turns a RGB color to its CMYK counterpart

[ back to function list ]

Syntax

COLOR_rgb2cmyk( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component. Optional if $r is an array.
$b int Integer of the blue component. Optional if $r is an array.
Return

(array) CMYK parts (associative array: 'c', 'm', 'y', 'k')

Examples Executed
Example #1
var_dump( COLOR_rgb2cmyk( 255,128,255 ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=4)
  'c' => float 0
  'm' => float 0.49803921568627
  'y' => float 0
  'k' => float 0
Example #2
// array:  'c' => int 0, 'm' => float 0.49803921568627, 'y' => int 0, 'k' => int 0
var_dump( $aCMYK = COLOR_rgb2cmyk( 255,128,255 ) );

echo LSUnitTesting::assert( $aCMYK['c'] === 0.0 &&
                            $aCMYK['m'] > 0.498 &&
                            $aCMYK['m'] < 0.5   &&
                            $aCMYK['y'] === 0.0 &&
                            $aCMYK['k'] === 0.0                 ,
                            'ASSERTION SUCCESS: cmyk correct'   ,
                            'ASSERTION SUCCESS: cmyk incorrect' ,
                            'GuideAssert' );

var_dump( $aCMYK = COLOR_rgb2cmyk( 245,134,52 ) );

echo LSUnitTesting::assert( $aCMYK['c'] === 0.0     &&
                            $aCMYK['m'] > 0.453     &&
                            $aCMYK['m'] < 0.454     &&
                            $aCMYK['y'] > 0.787     &&
                            $aCMYK['y'] < 0.788     &&
                            $aCMYK['k'] > 0.039     &&
                            $aCMYK['k'] < 0.040                 ,
                            'ASSERTION SUCCESS: cmyk correct'   ,
                            'ASSERTION SUCCESS: cmyk incorrect' ,
                            'GuideAssert' );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:2:
array (size=4)
  'c' => float 0
  'm' => float 0.49803921568627
  'y' => float 0
  'k' => float 0

GuideAssert() ... ASSERTION SUCCESS: cmyk correct

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:13:
array (size=4)
  'c' => float 0
  'm' => float 0.4530612244898
  'y' => float 0.78775510204082
  'k' => float 0.03921568627451

GuideAssert() ... ASSERTION SUCCESS: cmyk correct

Unit Testing

2 assertions: 2 successful; 0 failed

See Also

COLOR_rgb2hex(), COLOR_cmyk2rgb()

COLOR_rgb2gray(): Transforms a color into a grey flavor

[ back to function list ]

Syntax

COLOR_rgb2gray( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component
$b int Integer of the blue component
Return

(array) The resulting color as an RGB associative array
r … red value
g … green value
b … blue value

Example Executed
$aRGB = COLOR_rgb2gray( 155,200,15 );
var_dump( $aRGB );
echo LSUnitTesting::assert( $aRGB['r'] === 165                      ,
                            'ASSERTION SUCCESS: gray tint correct'  ,
                            'ASSERTION SUCCESS: gray tint incorrect',
                            'GuideAssert' );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:2:
array (size=3)
  'r' => int 165
  'g' => int 165
  'b' => int 165

GuideAssert() ... ASSERTION SUCCESS: gray tint correct

Unit Testing

1 assertions: 1 successful; 0 failed

COLOR_rgb2hex(): Turns a RGB color to its HTML hexa counterpart

[ back to function list ]

Syntax

COLOR_rgb2hex( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component
$b int Integer of the blue component
Return

(string) HTML color (hexadecimal value)

Examples Executed
Example #1
echo '<p>' . COLOR_rgb2hex( 255,128,255 ) . '</p>'; // Prints "#ff80ff"

#ff80ff

Example #2
echo '<p>' . COLOR_rgb2hex( array( 'r' => 255,'g' => 128,'b' => 255) ) . '</p>'; // Prints "#ff80ff"

#ff80ff

Assertions

COLOR_rgb2hex( array( 'r' => 255,'g' => 128,'b' => 255 ) ) === '#ff80ff' successful

COLOR_rgb2hex( 255,128,255 ) === '#ff80ff' successful

Unit Testing

2 assertions: 2 successful; 0 failed

See Also

COLOR_rgb2hsl(), COLOR_int2rgb(), COLOR_int2rgb2()

COLOR_rgb2hsl(): Turns a RGB color to its HSL constituents

[ back to function list ]

Syntax

COLOR_rgb2hsl( $r,$g,$b )

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component if $r is an integer
$b int Integer of the blue component if $r is an integer
Return

(array) Resulting color as a RGB associative array
'h' ... hue value
's' ... saturation value
'l' ... luminosity value

Example Executed
var_dump( $aHSL= COLOR_rgb2hsl( 255,128,255 ) );

D:\websites\vaesoli.org\www\httpdocs\vaesoli\include\LSFunction.class.php(211) : eval()'d code:1:
array (size=3)
  'h' => float 0.83333
  's' => float 1
  'l' => float 0.75098
Unit Testing

WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}) or with GuideAssert() function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}).

COLOR_rgb2hsv(): Turns an RGB color into hue, saturation and value

[ back to function list ]

Credits

Adapted from

Docs

More doc on .

Syntax

COLOR_rgb2hsv( $r,$g,$b )

Alias

COLOR_rgb2hsb()

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component if $r is an integer
$b int Integer of the blue component if $r is an integer
Return

(int) The resulting color as an integer

Example(s)
Example #1
$aRGB = COLOR_hex2rgb( '#ff80ff' ); // $aRGB['r'] = 255,$aRGB['g'] = 128,$aRGB['b'] = 255
Unit Testing

WARNING: No Unit Testing found. Please provide assertions with assertion constructs ({*assert ... *}) or with GuideAssert() function calls in exec constructs ({*exec LSUnitTesting::assert(...); *}).

See Also

COLOR_int2rgb(), COLOR_int2rgb2()

COLOR_rgb2int(): Turns an RGB color into an integer

[ back to function list ]

Syntax

COLOR_rgb2int( $r,$g,$b )

Alias

COLOR_rgb(), rgb()

Parameters
NameTypeDescription
$r mixed Array of RGB colors or integer of the red component
$g int Integer of the green component if $r is an integer
$b int Integer of the blue component if $r is an integer
Return

(int) The resulting color as an integer

Example Executed
echo COLOR_rgb2int( 255,0,255 );

16711935
Assertions

COLOR_rgb2int( 255,255,255 ) === 16777215 successful

COLOR_rgb2int( 255,0,255 ) === 16711935 successful

COLOR_rgb2int( 0,255,255 ) === 16776960 successful

COLOR_rgb2int( 0,255,0 ) === 65280 successful

COLOR_rgb2int( 0,0,255 ) === 16711680 successful

COLOR_rgb2int( 255,0,255 ) === 16711935 successful

Unit Testing

6 assertions: 6 successful; 0 failed

See Also

COLOR_int2rgb()

Précédent Suivant