gd_bgMerge.php
1.21 KB
1
2
3
4
5
6
7
8
9
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
<?php
require_once dirname (__FILE__) . "/../config.php";
require_once LIBDIR . "errException.php";
setErrExceptionMapping ();
// --- Data ----------------------------------
if (isset ($_REQUEST['img']))
$img = $_REQUEST['img'];
else
$img = -1;
if (isset ($_REQUEST['col']))
$col = $_REQUEST['col'];
else
$col = 'aaaaaa';
// -------------------------------------------
// Load Image and get it's size
if ($img !== -1)
{
$size = getimagesize(IMGDIR . $img);
$width = $size[0];
$height = $size[1];
unset ($size);
$loadIm = imagecreatefrompng (IMGDIR . $img);
}
else
{
$width = 1;
$height = 1;
$loadIm = imagecreatetruecolor ($width, $height);
$color = imagecolorallocatealpha ($loadIm, 0, 0, 0, 127);
imagefill ($loadIm, 0, 0, $color);
unset ($color);
}
imagealphablending ($loadIm, TRUE);
$bgImg = imagecreatetruecolor ($width, $height);
preg_match_all ('/[A-Za-z0-9]{2,2}/', $col, $rgb);
$color = imagecolorallocate (
$bgImg, hexdec ($rgb[0][0]), hexdec ($rgb[0][1]), hexdec ($rgb[0][2]));
imagefill ($bgImg, 0, 0, $color);
unset ($color);
imagecopy ($bgImg, $loadIm, 0, 0, 0, 0, $width, $height);
imagedestroy($loadIm);
resetErrExceptionMapping ();
header ("Content-Type: image/png");
imagepng ($bgImg);
?>