PHP Created by SVG as Background Image

I want to dynamically change the color of the SVG depending on which background color is selected. This works, but it will not work as a background image, as the .php file name

Here is my PHP code that makes my image, I did not include all the paths:

<?php 
header('Content-type: image/svg+xml');

function adjustBridgtness($rgb, $steps) {
    //Only allow RGB value to be sent
    if (count($rgb) == 3) {
        //Negative darker, positive brighter
        $steps = max(-255, min(255, $steps));

        //New color
        $new_color = array();

        foreach($rgb as $color) {
            //$color = hexdec($color); 
            $color = max(0,min(255,$color + $steps));
            $new_color[] = $color;
        }

        return $new_color;
    }
}
//$colors[0] = array(67,189,151); //Row 1

$colors[0] = adjustBridgtness(array(67,189,151),0); //Row 1
$colors[1] = array(81,193,159); //Row 2
$colors[2] = array(95,199,165); //Row 3
$colors[3] = array(107,203,173); //Row 4
$colors[4] = array(127,211,185); //Row 5
$colors[5] = array(81,193,159); //Diagonal Lines
$colors[6] = array(127,211,185); //Verticle Line

?>
<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    width="796px" height="404px" viewBox="0 0 796 404">
    <path fillRule="evenodd" d="M 349.5 153.12C 349.5 153.12 396.88 200.5 396.88 200.5 396.88 200.5 349.5 247.88 349.5 247.88 349.5 247.88 302.12 200.5 302.12 200.5 302.12 200.5 349.5 153.12 349.5 153.12Z" fill="rgb(<?=$colors[0][0]?>,<?=$colors[0][1]?>,<?=$colors[0][2]?>)"/>
    <path fillRule="evenodd" d="M 251.5 153.12C 251.5 153.12 298.88 200.5 298.88 200.5 298.88 200.5 251.5 247.88 251.5 247.88 251.5 247.88 204.12 200.5 204.12 200.5 204.12 200.5 251.5 153.12 251.5 153.12Z" fill="rgb(<?=$colors[0][0]?>,<?=$colors[0][1]?>,<?=$colors[0][2]?>)"/>
</svg>

I just put it in the background-image property like this:

background-image:url(images/image.php);

This does not work though, since it does not appear, what did I do wrong?

PS Only the website administrator can change the background color, would it be better to generate an SVG and overwrite the existing file, for example background.svg, when the color is changed, and not generate colors every time the page is loaded?

+4
source share
1

mmh, ... ( )

<div style="width:400px;height:400px;background-image:url(http://karl.uphero.com/images/background_banner1.php)"></div>
Hide result
+1

Source: https://habr.com/ru/post/1608794/


All Articles