Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4001312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:53:21+00:00 2026-05-20T07:53:21+00:00

A quesion about RGB color and finding the simplest, tiniest, php conversion code for

  • 0

A quesion about RGB color and finding the simplest, tiniest, php conversion code for manipulating the lightness/darkness of a given RGB hue.

Imagine a variable $colorA containning a valid six char RGB color, like F7A100 which we want to make a bit lighter and/or darker:

$color  = B1B100;                     // original RGB color manually set.

Then, at any page have that color bit darker/lighter on the fly:

$colorX = someFunction($color, +10);  // original color 10 steps lighter
$colorY = someFunction($color, -25);  // original color 25 steps darker

What would be YOUR way of solving this? Keep the RGB as is or first change it to HSL? Hints and suggestions are welcome. Your sample/code is welcome too.

This really focuses to the TINIES / SIMPLES / SHORTEST possible code to just make the same hue bit darker/lighter.

I deliberately do not suggest my code, as I want to keep possibilities open in here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T07:53:21+00:00Added an answer on May 20, 2026 at 7:53 am

    For slight alteration of brightness you can convert the hexadecimal values to decimal, manipulate them and convert back to hexadecimal like this:

    function alterBrightness($color, $amount) {
        $rgb = hexdec($color); // convert color to decimal value
    
        //extract color values:
        $red = $rgb >> 16;
        $green = ($rgb >> 8) & 0xFF;
        $blue = $rgb & 0xFF;
    
        //manipulate and convert back to hexadecimal
        return dechex(($red + $amount) << 16 | ($green + $amount) << 8 | ($blue + $amount));
    }
    
    echo alterColor('eeeeee', -10); //outputs e4e4e4
    

    Beware that this code does not handle overflow for one color – if one color value becomes less than 0 or more than 255 you will get an invalid color value. This should be easy enough to add.

    For drastic changes in brightness, convert to HSL and manipulate the lightness.

    Using the functions from the Drupal code, this can be done like this:

    $hsl = _color_rgb2hsl(_color_unpack('eeeeee'));
    $hsl[2] -= 10;
    $rgb = _color_pack(_color_hsl2rgb($hsl));
    echo $rgb;  //outputs e4e4e4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently asked a question about Oracle Encryption. Along the way to finding a
In my current project I have data about colors. Each color is either a
it's a quesion about mercurial. I'm not a unix - guy, but use a
A question about this R code: library(RODBC) ch <- tryCatch(odbcConnect(RTEST), warning=function(w){print(FAIL! (warning));return(NA)}, error=function(e){print(paste(ERROR:,geterrmessage()));return(NA)}) df
Quick question about Ruby forking - I ran across a bit of forking code
Another question about PHP and XML... Is it posible to exclude children based on
My question about the reconfiguration delay when switching between Access 2003 and 2007 the
I recently asked a question about IIf vs. If and found out that there
I was reading this question about how to parse URLs out of web pages
I recently asked a question about what I called method calls. The answer referred

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.