# Make hex colours lighter with PHP (using existing code)

**URL:** https://forum.kirupa.com/t/make-hex-colours-lighter-with-php-using-existing-code/323654
**Category:** programming
**Created:** [July 11, 2011, 12:59pm UTC](https://forum.kirupa.com/t/make-hex-colours-lighter-with-php-using-existing-code/323654 "2011-07-11T12:59:08Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Tyg3r](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tyg3r/32/1341_2.png) [@Tyg3r](https://forum.kirupa.com/u/Tyg3r)
#### Post date: [July 11, 2011, 12:59pm UTC](https://forum.kirupa.com/t/make-hex-colours-lighter-with-php-using-existing-code/323654/1 "2011-07-11T12:59:08Z")

</div>

Hi,

So I’ve had a good look around and found various versions of similar functions that do what I want. But one particular method I’ve found is nice and neat.

I’m using [Jonas John “Darker Color” snippit](http://www.jonasjohn.de/snippets/php/darker-color.htm), but I’d like to reverse his method to create lighter colours, not darker.

```php
function ColorDarken($color, $dif=20){
 
    $color = str_replace('#', '', $color);
    if (strlen($color) != 6){ return '000000'; }
    $rgb = '';
 
    for ($x=0;$x<3;$x++){
        $c = hexdec(substr($color,(2*$x),2)) - $dif;
        $c = ($c < 0) ? 0 : dechex($c);
        $rgb .= (strlen($c) < 2) ? '0'.$c : $c;
    }
 
    return '#'.$rgb;
}

```

My attempts to just turn minuses (-) to pluses (+), and devisions (/) to times (\*) is futile.

Any input on this would be greatly appreciated.

Cheers,

Mark
