gd_bgMerge.php 1.21 KB
<?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);

?>