Jump to content


Photo

PNG Alpha


  • Please log in to reply
No replies to this topic

#1 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 23 August 2006 - 06:37 PM

Alrighty, I'm working on a clock made with PHP, but the transparency on all of it is completely messed up.
Well, here's the code, any help would be great:
<?
	header('Content-type: image/png');

	$hour = date('g');
	$minute = date('i');
	$second = date('s');
	$srotate = 6 * $second;
	$mrotate = 6 * $minute + 0.1 * $second;
	$hrotate = 30 * $hour + 0.5 * $minute + (0.5/60) * $second;
	
	$face = imagecreatefrompng('clock/face.png');
	$hourhand = imagecreatefrompng('clock/hour.png');
	$minutehand = imagecreatefrompng('clock/minute.png');
	$secondhand = imagecreatefrompng('clock/second.png');

	imagealphablending($face, true);
	imagealphablending($hourhand, true);
	imagealphablending($minutehand, true);
	imagealphablending($secondhand, true);

	$hhr = imagerotate($hourhand, $hrotate, -1);
	$mhr = imagerotate($minutehand, $mrotate, -1);
	$shr = imagerotate($secondhand, $srotate, -1);

	$hhrleft = imagesx($face) / 2 - imagesx($hhr) / 2;
	$mhrleft = imagesx($face) / 2 - imagesx($mhr) / 2;
	$shrleft = imagesx($face) / 2 - imagesx($shr) / 2;

	imagecopymerge($face, $hhr, $hhrleft, 0, 0, 0, imagesx($hourhand), imagesy($hourhand), 100);
	imagecopymerge($face, $mhr, $mhrleft, 0, 0, 0, imagesx($minutehand), imagesy($minutehand), 100);
	imagecopymerge($face, $shr, $shrleft, 0, 0, 0, imagesx($secondhand), imagesy($secondhand), 100);

	imagepng($face);
	imagedestroy($face);
	imagedestroy($hourhand);
	imagedestroy($minutehand);
	imagedestroy($secondhand);
?>
Its not very complex, but it should theoretically work. Unfortunately GD seems to really hate alpha channels...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users