01:
02:
03:
04:
05:
06:
07:
08:
09:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
<?
function pngcolorizealpha($file$color) {
/*
Function:    pngcolorizealpha
Author:    CoD (cod at crescentofdarkness dot cjb dot net)
Summary:    Blends a truecolor png image with a coloured background using alpha channel

Input:
--------------------------
$file - string - path to the png image
$color- string - color in hex notation, without the #

Output:
--------------------------
a png image

*/

// first of all let's convert the background color
$background = array(
     
'red'   => hexdec(substr($color,0,2)),
     
'green' => hexdec(substr($color,2,2)),
     
'blue'  => hexdec(substr($color,4,2))
);

$im1 imagecreatefrompng($file) or die('Cannot Initialize new GD image stream');
$im2 imagecreatetruecolor(imagesx($im1), imagesy($im1));
$col1 imagecolorallocate($im2$background['red'], $background['green'], $background['blue']);

imagefill($im2,0,0,$col1);

// for each color in the original png
for ($i=0$iimagecolorstotal($im1); $i++) {

    
// find r,g,b and alpha value 
    
$foreground imagecolorsforindex($im1$i);

    
// blend fore and back colors using alpha value
    
$r = (($foreground['red'] / 127) * (127 $foreground['alpha'])) + (($background['red'] / 127)* $foreground['alpha']);
    
$g = (($foreground['green'] / 127) * (127 $foreground['alpha'])) + (($background['green'] / 127)* $foreground['alpha']);
    
$b = (($foreground['blue'] / 127) * (127 $foreground['alpha'])) + (($background['blue'] / 127)* $foreground['alpha']);

    
// allocate this new color in the destination image
    
imagecolorallocate($im2$r,$g,$b);
}

imagecopy($im2$im10000imagesx($im1), imagesy($im1));

header ("Content-type: image/png");
imagepng($im2);

imagedestroy($im1);
imagedestroy($im2);
}
/* 
$bild = imagecreatefrompng('images/footer.png');
header('Content-Type: image/png');


$img = $bild;
$white = imagecolorallocate( $img, 255, 255, 255 );
    imagefill( $img, 0, 0, $white );
imagepng($img); */

if(isset($_GET['file']) && isset($_GET['color'])){
  if(
$_GET['file'] != 'background.png' && $_GET['file'] != "footer.png" && $_GET['file'] != "header.png"){
    die;
  }
  
pngcolorizealpha('images/'.$_GET['file'],$_GET['color']);
}
else{
  require_once(
'gradient.class.php');
  
$image = new gd_gradient_fill(680,61,"vertical",$_GET['color1'],$_GET['color2'],0);
  
header('Content-Type:image/png');
  
imagepng($image);
}