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

  • Home
  • SEARCH
  • 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 737713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:45:11+00:00 2026-05-14T07:45:11+00:00

I am looking to find a why to calculate a suitable background colour and

  • 0

I am looking to find a why to calculate a suitable background colour and a colour for the text that would go over the top, obviously I need to take into account readability and accessibility.

I would need to pick the two colours from the array, the colours are stored in their hex representations.

#CC9966
#996633
#FFCC99
#CCCC99
#000000
#333333
#666633
#663333
#CC9933
#FFCCCC

I can use a PHP library like GD / imageMagick?

Any suggestions (Please note I am using PHP)

  • 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-14T07:45:11+00:00Added an answer on May 14, 2026 at 7:45 am

    First of all I think you should take a look at this excellent blog post at Particletree.

    That being said, I would use their smarty_modifier_contrast() function and modify it a little bit to address your specific needs, something like:

    function color_contrast($bgcolor, $color1, $color2, $color3, ...)
    {
        return (hexdec($bgcolor) > 0xffffff / 2) ? min(array_slice(func_get_args(), 1)) : max(array_slice(func_get_args(), 1));
    }
    

    So you would just need to use any random color for the background (don’t forget to drop the #!) and then pass all the other colors to the array, in this case I’ve used a variable number of arguments but you can change it so that it accepts a single array of colors – it will then automatically pick the darkest or the lightest color depending on the $bgcolor and provide a good enough contrast for readability:

    function color_contrast($bgcolor, $colors = array())
    {
        return (hexdec($bgcolor) > 0xffffff / 2) ? min($colors) : max($colors);
    }
    

    To pick the $bgcolor, you can do it randomly like I said before of use a second function to help you with this task like saturation or luminance, that really depends what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to find the Javascript Event I need to put into jQuery's .bind
Hi and thanks for looking! Background I have a computing task that requires either
I am looking to find a way to programatically (C++) control/secure access to the
I'm looking to find something along the lines of Checkstyle for Visual Studio. I've
I'm looking to find a galleria replacement, hopefully using jQuery but other javascript frameworks
I am looking to find out if a web page has changed, I was
I'm looking to find a way to round up to the nearest 500.I've been
I am looking to find this in a string: XXXX-XXX-XXX Where the X is
I am looking to find the last positional parameter. I know to find the
I'm using NSURLConnection to pull data from a webpage. I'm looking to find a

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.