scholarslab / cville_rally_theme

Omeka theme for Charlottesville rally archive
4 stars 0 forks source link

Create function for banner image color gradient #19

Closed eam5 closed 5 years ago

eam5 commented 5 years ago

Create custom php function for theme_header_background() to include a color gradient/color transparency linked to theme option for 'background_color'

eam5 commented 5 years ago

I found a workaround for this by assigning the gradient color to the text background instead of the header image and used a function that converts hex color to rgba:

In the header.php style: #introduction p { background-image: linear-gradient(<?php echo hex2rgba($backgroundColor, 0.6); ?>, <?php echo hex2rgba($backgroundColor, 0.8); ?>); color: <?php echo $textColor; ?>; } In functions.php:

`
function hex2rgba($color, $opacity = false) {

$default = 'rgb(0,0,0)';

//Return default if no color provided
if(empty($color))
      return $default; 

//Sanitize $color if "#" is provided 
    if ($color[0] == '#' ) {
        $color = substr( $color, 1 );
    }

    //Check if color has 6 or 3 characters and get values
    if (strlen($color) == 6) {
            $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
    } elseif ( strlen( $color ) == 3 ) {
            $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
    } else {
            return $default;
    }

    //Convert hexadec to rgb
    $rgb =  array_map('hexdec', $hex);

    //Check if opacity is set(rgba or rgb)
    if($opacity){
        if(abs($opacity) > 1)
            $opacity = 1.0;
        $output = 'rgba('.implode(",",$rgb).','.$opacity.')';
    } else {
        $output = 'rgb('.implode(",",$rgb).')';
    }

    //Return rgb(a) color string
    return $output; 
}

`