Need Help

Can someone please help me and tell me why this code doesnt work?
I’m trying to overlay an inamge with a clock.
Thanks for any help.

[php]
// File and rotation
$overFilename = ‘http://spatialdistortion.zxq.net/GC438PP/Booty-Plain.png’;
$underFilename = ‘http://spatialdistortion.zxq.net/GC438PP/Booty-Map2.png’;
$degrees = $_GET[“angle”];
$secs = ((date(“G”) * 3600) + (date(“i”) * 60) + date(“s”)) / 240;

$startColor = “0a053a”;
$endColor = “fff600”;

$step = “43200”;if (date(“H”) > 12){
$startColor = “fff600”;
$endColor = “0a053a”;
}

$theR0 = ($startColor & 0xff0000) >> 16;
$theG0 = ($startColor & 0x00ff00) >> 8;
$theB0 = ($startColor & 0x0000ff) >> 0;
$theR1 = ($endColor & 0xff0000) >> 16;
$theG1 = ($endColor & 0x00ff00) >> 8;
$theB1 = ($endColor & 0x0000ff) >> 0;
$overlayImg = imagecreatefrompng($overFilename);
$dest = imagecreatefrompng($underFilename);
$clockImg = createClock();
$timeTextImg = createTimeTextImage();
imagecopymerge($overlayImg, $clockImg, 85,205, 0, 0, 250, 70, 100);
imagecopymerge($overlayImg, $timeTextImg, 93,170, 0, 0, 150, 40, 100);
$rotatedImage = rotateImage($overlayImg, $secs);
$black = imagecolorallocate($rotatedImage, 0, 0, 0);
imagecolortransparent($rotatedImage, $black);
imagecopymerge($dest, $rotatedImage, 0, 0, 1, 1, 335, 335, 100);
imagealphablending( $dest, false );
imagesavealpha( $dest, true );
header(‘Content-Type: image/png’);
imagepng($dest );

function createTimeTextImage(){
// Create the image
$image = imagecreatetruecolor(150, 40);
// Create some colors
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 39, 9, 225);
$orange = imagecolorallocate($image, 225, 151, 9);
$grey = imagecolorallocate($image, 192, 192, 192);
imagefilledrectangle($image, 0, 0, 499, 70, $white);
$curTime = “TIME”;
// Replace path by your own font path
$font = ‘http://spatialdistortion.zxq.net/GC438PP/JandaManateeBubble.ttf’;
imagecolortransparent($image, $white);
// Add the text
imagettftext($image, 25, 0, 34, 31, $orange, $font, $curTime);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($image);
imagedestroy($image);
return $image;
}

function createClock(){
// Create the image
$image = imagecreatetruecolor(250, 70);
// Create some colors
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 39, 9, 225);
$orange = imagecolorallocate($image, 225, 151, 9);
$grey = imagecolorallocate($image, 192, 192, 192);
imagefilledrectangle($image, 0, 0, 499, 70, $white);
$hour = (date(“H”)) ;
$min = (date(“i”)) ;
$curTime = $hour . “:” . $min;

// Replace path by your own font path	
$font = 'http://spatialdistortion.zxq.net/GC438PP/JandaManateeSolid.ttf';	
imagecolortransparent($image, $white);
// Add the text	
imagettftext($image, 50, 0, 0, 60, $orange, $font,  $curTime);
// Using imagepng() results in clearer text compared with imagejpeg()	
imagepng($image);	
imagedestroy($image);
return $image;

}

function rotateImage ($image, $angle){
while ($angle > 360){
$angle = $angle - 360;
}

while ($angle < 0 ){
	$angle = $angle + 360;
}

if ( ($angle < 0) || ($angle > 360) ){
	exit ("Error, angle passed out of range: [0,360]");

}
$width = imagesx ($image);
$height = imagesy ($image);
$dstImage = imagecreatetruecolor ($width, $height);
if ( ($angle == 0) || ($angle == 360) ){
// Just copy image to output:
imagecopy ($dstImage, $image, 0, 0, 0, 0, $width, $height);
} else {
$centerX = floor ($width / 2);
$centerY = floor ($height / 2);
// Run on all pixels of the destination image and fill them:
for ($dstImageX = 0; $dstImageX < $width; $dstImageX++){
for ($dstImageY = 0; $dstImageY < $height; $dstImageY++){
// Calculate pixel coordinate in coordinate system centered at the image center:
$x = $dstImageX - $centerX;
$y = $centerY - $dstImageY;

			if ( ($x == 0) && ($y == 0) ){
				// We are in the image center, this pixel should be copied as is:
				$srcImageX = $x;
				$srcImageY = $y;
			} else {		
				$r = sqrt ($x * $x + $y * $y); // radius - absolute distance of the current point from image center
				$curAngle = asin ($y / $r); // angle of the current point [rad]
				if ($x < 0) {
					$curAngle = pi () - $curAngle;
				}

				$newAngle = $curAngle + $angle * pi () / 180; 
				// new angle [rad]
				
				// Calculate new point coordinates (after rotation) in coordinate system at image center
				$newXRel = floor ($r * cos ($newAngle));
				$newYRel = floor ($r * sin ($newAngle));

				// Convert to image absolute coordinates
				$srcImageX = $newXRel + $centerX;
				$srcImageY = $centerY - $newYRel;
			}

			$pixelColor = imagecolorat  ($image, $srcImageX, $srcImageY); 
			// get source pixel color
			imagesetpixel ($dstImage, $dstImageX, $dstImageY, $pixelColor); 
			// write destination pixel		
		}
	}
}

return $dstImage;
}

function interpolate($pBegin, $pEnd, $pStep, $pMax) {
if ($pBegin < $pEnd) {
return (($pEnd - $pBegin) * ($pStep / $pMax)) + $pBegin;
} else {
return (($pBegin - $pEnd) * (1 - ($pStep / $pMax))) + $pEnd;
}
}

?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service