Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

HEX to RGB

Posted on August 15, 2013October 26, 2015 By David Kittell
function html2rgb($color)
{
    if ($color[0] == '#')
        $color = substr($color, 1);
    if (strlen($color) == 6)
        list($r, $g, $b) = array($color[0].$color[1],
                                 $color[2].$color[3],
                                 $color[4].$color[5]);
    elseif (strlen($color) == 3)
        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
    else
        return false;
    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
    return array($r, $g, $b);
}

function rgb2html($r, $g=-1, $b=-1)
{
    if (is_array($r) && sizeof($r) == 3)
        list($r, $g, $b) = $r;
    $r = intval($r); $g = intval($g);
    $b = intval($b);
    $r = dechex($r<0?0:($r>255?255:$r));
    $g = dechex($g<0?0:($g>255?255:$g));
    $b = dechex($b<0?0:($b>255?255:$b));
    $color = (strlen($r) < 2?'0':'').$r;
    $color .= (strlen($g) < 2?'0':'').$g;
    $color .= (strlen($b) < 2?'0':'').$b;
    return '#'.$color;
}
Originally Posted on August 15, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PHP

Post navigation

Previous post
Next post

Related Posts

SMTP Mail

Posted on February 22, 2013October 26, 2015

MailMessage m = new MailMessage(); SmtpClient sc = new SmtpClient(); m.From = new MailAddress("email@email.com", "Name Of Person"); m.To.Add(new MailAddress("email@email.com", "Name Of Person")); m.CC.Add(new MailAddress("email@email.com", "Name Of Person")); m.Subject = "Email Subject"; m.Body = sResultsHTML; AlternateView av = AlternateView.CreateAlternateViewFromString(sResultsHTML, null, MediaTypeNames.Text.Html); m.AlternateViews.Add(av); sc.Port = 25; sc.Host = "mail.email.com"; // Email server…

Read More

Ektron – Category Template

Posted on October 31, 2014October 26, 2015

<%@ Page Language="C#" MasterPageFile="~/masterpages/content.master" AutoEventWireup="true" CodeFile="boardlanding.aspx.cs" Inherits="templates_categorylanding" Title="Category Landing Page" %> <%@ Register Assembly="Ektron.Cms.Controls" Namespace="Ektron.Cms.Controls" TagPrefix="CMS" %> <%@ Register Src="~/usercontrols/breadcrumb.ascx" TagName="Breadcrumb" TagPrefix="uc" %> <asp:Content ID="Header" ContentPlaceHolderID="ContentHeaderContentPlaceHolder" runat="server"> <!– categorylanding –> <img class="banner" alt="banner" src="/img/banner_01.jpg"> </asp:Content> <asp:Content ID="Left" ContentPlaceHolderID="LeftContentPlaceHolder" runat="Server"> <div id="crumbs"> <uc:Breadcrumb ID="breadcrumbControl" runat="server" /> </div> <img class="divider upper" alt=""…

Read More

Powershell Download Script

Posted on September 11, 2015

# If you haven’t already done so you will need to run this to be able to execute PowerShell scripts # You will need to run PowerShell as administrator to run this script set-executionpolicy remotesigned Pass variables to the script <# .SYNOPSIS Downloads one file from a defined URL to…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes