Your cart is empty

While developing a Joomla Template I needed lighter and darker border colors of menu items. Border colors should have been darker and lighter version of background color. Based on this thread I have tried and used successfully php to lighten and darken colors. The main php code is below. The key point is using 255 and 0 in php functions to lighten and darken colors.

This is php function to Lighten given colors.

function luminanceLight($hexcolor, $percent)
{
  if ( strlen( $hexcolor ) < 6 ) {
    $hexcolor = $hexcolor[0] . $hexcolor[0] . $hexcolor[1] . $hexcolor[1] . $hexcolor[2] . $hexcolor[2];
  }
  $hexcolor = array_map('hexdec', str_split( str_pad( str_replace('#', '', $hexcolor), 6, '0' ), 2 ) );

  foreach ($hexcolor as $i => $color) {
    $from = $percent < 0 ? 0 : $color;
    $to = $percent < 0 ? $color : 255;
    $pvalue = ceil( ($to - $from) * $percent );
    $hexcolor[$i] = str_pad( dechex($color + $pvalue), 2, '0', STR_PAD_LEFT);
  }

  return '#' . implode($hexcolor);
}

 

and this php function to Darken given colors.

function luminanceDark($hexcolor, $percent)
{
  if ( strlen( $hexcolor ) < 6 ) {
    $hexcolor = $hexcolor[0] . $hexcolor[0] . $hexcolor[1] . $hexcolor[1] . $hexcolor[2] . $hexcolor[2];
  }
  $hexcolor = array_map('hexdec', str_split( str_pad( str_replace('#', '', $hexcolor), 6, '0' ), 2 ) );

  foreach ($hexcolor as $i => $color) {
    $from = $percent < 0 ? 0 : $color;
    $to = $percent < 0 ? $color : 0;
    $pvalue = ceil( ($to - $from) * $percent );
    $hexcolor[$i] = str_pad( dechex($color + $pvalue), 2, '0', STR_PAD_LEFT);
  }

  return '#' . implode($hexcolor);
}

I wanted to have one light and one dark border for menu items originating from background color of navigation menu. I have a $navbar_color.

$navbar_color    = $this->params->get('NavbarColor') ?: '';

So my border colors should be like this. The 0.1 and 0.15 values means 10% lighter and 15% darker colors.

$border_color_light=luminanceLight($navbar_color,0.1);
$border_color_dark=luminanceDark($navbar_color,0.15);

 One last thing you should use that php constants as inline css or dynamic CSS.

Copyright © 2013 Joomlatema.Net 

  Terms of Service l Contact Us

JoomlaTema and this site is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited license granted by Open Source Matters, Inc.