Ignore:
Timestamp:
Mar 7, 2007 11:32:07 AM (17 years ago)
Author:
quinn
Message:

Q - fixed some fv->err() usage bugs, increased resolution of textColor(), improved formatting of some Utilities.inc.php functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Utilities.inc.php

    r224 r235  
    150150function getTextColor($text, $method=1)
    151151{
    152     $r = substr(md5($text), 0, 1);
    153     $g = substr(md5($text), 1, 1);
    154     $b = substr(md5($text), 2, 1);
     152    $hash = md5($text);
     153    $rgb = array(
     154        substr($hash, 0, 1),
     155        substr($hash, 1, 1),
     156        substr($hash, 2, 1),
     157        substr($hash, 3, 1),
     158        substr($hash, 4, 1),
     159        substr($hash, 5, 1),
     160    );
    155161
    156162    switch ($method) {
    157     case 2 :
    158         if (hexdec($r) > hexdec('c')) {
    159             $r = dechex(hexdec('f') - hexdec($r));
    160         }
    161         if (hexdec($g) > hexdec('c')) {
    162             $g = dechex(hexdec('f') - hexdec($g));
    163         }
    164         if (hexdec($b) > hexdec('c')) {
    165             $b = dechex(hexdec('f') - hexdec($b));
    166         }
    167         break;
    168 
    169163    case 1 :
    170164    default :
    171         $r = dechex(round(hexdec($r) * .8));
    172         $g = dechex(round(hexdec($g) * .8));
    173         $b = dechex(round(hexdec($b) * .6));
     165        // Reduce all hex values slighly to avoid all white.
     166        array_walk($rgb, create_function('&$v', '$v = dechex(round(hexdec($v) * 0.87));'));
    174167        break;
    175     }
    176 
    177     return $r . $r . $g . $g . $b . $b;
     168    case 2 :
     169        foreach ($rgb as $i => $v) {
     170            if (hexdec($v) > hexdec('c')) {
     171                $rgb[$i] = dechex(hexdec('f') - hexdec($v));
     172            }
     173        }
     174        break;
     175    }
     176
     177    return join('', $rgb);
    178178}
    179179
     
    392392 * @return array              URL with array elements as URL key=value arguments.
    393393 */
    394 function urlEncodeArray($data, $prefix='', $_return=true) {
     394function urlEncodeArray($data, $prefix='', $_return=true)
     395{
    395396
    396397    // Data is stored in static variable.
     
    428429 * @return string url         A string ready to append to a url.
    429430 */
    430 function urlEncodeArrayToString($data, $prefix='') {
     431function urlEncodeArrayToString($data, $prefix='')
     432{
    431433
    432434    $array_args = urlEncodeArray($data, $prefix);
     
    708710 * will see data before the page is finished processing.
    709711 */
    710 function flushBuffer() {
     712function flushBuffer()
     713{
    711714    echo str_repeat('          ', 205);
    712715    flush();
Note: See TracChangeset for help on using the changeset viewer.