<?php
	include "library.php";

	$cxn = start_code( true );

	$pathroot = val( $_SESSION, "pathroot" );

		/* change the version number to force browser reload of gifs */

		/* when changing the version number the library function */
		/* button_filename() needs to be updated */


	$version = "v1";

		/* note: create two versions of each button */

	create_button_image( "Accept Chat", 130, $version."_accept_chat.gif" );
	create_button_image( "Activate Membership", 200, $version."_activate_membership.gif" );
	create_button_image( "Block", 130, $version."_block.gif" );
	create_button_image( "Blocked", 140, $version."_blocked.gif" );
	create_button_image( "Buy 1 Credit", 150, $version."_buy_1_credit.gif" );
	create_button_image( "Buy 10 Credits", 150, $version."_buy_10_credits.gif" );
	create_button_image( "Buy 100 Credits", 150, $version."_buy_100_credits.gif" );
	create_button_image( "Buy 25 Credits", 150, $version."_buy_25_credits.gif" );
	create_button_image( "Buy 50 Credits", 150, $version."_buy_50_credits.gif" );
	create_button_image( "Credits", 140, $version."_credits.gif" );
	create_button_image( "Delete Profile", 140, $version."_delete_profile.gif" );
	create_button_image( "Delete", 100, $version."_delete.gif" );
	create_button_image( "Donate", 95, $version."_donate.gif" );
	create_button_image( "Home", 80, $version."_home.gif" );
	create_button_image( "Login", 82, $version."_login.gif" );
	create_button_image( "Logout", 160, $version."_logout.gif" );
	create_button_image( "Manage Photos", 160, $version."_manage_photos.gif" );
	create_button_image( "Messages", 160, $version."_messages.gif" );
	create_button_image( "No", 70, $version."_no.gif" );
	create_button_image( "Received", 140, $version."_received.gif" );
	create_button_image( "Remember", 130, $version."_remember.gif" );
	create_button_image( "Remembered", 140, $version."_remembered.gif" );
	create_button_image( "Remove Selected", 165, $version."_remove_selected.gif" );
	create_button_image( "Reply to Kiss", 130, $version."_reply_to_kiss.gif" );
	create_button_image( "Request Chat", 130, $version."_request_chat.gif" );
	create_button_image( "Save", 80, $version."_save.gif" );
	create_button_image( "Search", 100, $version."_search.gif" );
	create_button_image( "Select File", 110, $version."_select_file.gif" );
	create_button_image( "Send Email", 130, $version."_send_email.gif" );
	create_button_image( "Send Kiss", 130, $version."_send_kiss.gif" );
	create_button_image( "Send Password", 150, $version."_send_password.gif" );
	create_button_image( "Send Reply", 125, $version."_send_reply.gif" );
	create_button_image( "Send", 75, $version."_send.gif" );
	create_button_image( "Sent", 140, $version."_sent.gif" );
	create_button_image( "Set as Primary", 140, $version."_set_as_primary.gif" );
	create_button_image( "Subscribe", 110, $version."_subscribe.gif" );
	create_button_image( "Upload", 90, $version."_upload.gif" );
	create_button_image( "View Profile", 130, $version."_view_profile.gif" );
	create_button_image( "Yes", 70, $version."_yes.gif" );


	create_button_image( "Accept Chat", 130, $version."_accept_chat_b.gif", true );
	create_button_image( "Activate Membership", 200, $version."_activate_membership_b.gif", true );
	create_button_image( "Block", 130, $version."_block_b.gif", true );
	create_button_image( "Blocked", 140, $version."_blocked_b.gif", true );
	create_button_image( "Buy 1 Credit", 150, $version."_buy_1_credit_b.gif", true );
	create_button_image( "Buy 10 Credits", 150, $version."_buy_10_credits_b.gif", true );
	create_button_image( "Buy 100 Credits", 150, $version."_buy_100_credits_b.gif", true );
	create_button_image( "Buy 25 Credits", 150, $version."_buy_25_credits_b.gif", true );
	create_button_image( "Buy 50 Credits", 150, $version."_buy_50_credits_b.gif", true );
	create_button_image( "Credits", 140, $version."_credits_b.gif", true );
	create_button_image( "Delete Profile", 140, $version."_delete_profile_b.gif", true );
	create_button_image( "Delete", 100, $version."_delete_b.gif", true );
	create_button_image( "Donate", 95, $version."_donate_b.gif", true );
	create_button_image( "Home", 80, $version."_home_b.gif", true );
	create_button_image( "Login", 82, $version."_login_b.gif", true );
	create_button_image( "Logout", 160, $version."_logout_b.gif", true );
	create_button_image( "Manage Photos", 160, $version."_manage_photos_b.gif", true );
	create_button_image( "Messages", 160, $version."_messages_b.gif", true );
	create_button_image( "No", 70, $version."_no_b.gif", true );
	create_button_image( "Received", 140, $version."_received_b.gif", true );
	create_button_image( "Remember", 130, $version."_remember_b.gif", true );
	create_button_image( "Remembered", 140, $version."_remembered_b.gif", true );
	create_button_image( "Remove Selected", 165, $version."_remove_selected_b.gif", true );
	create_button_image( "Reply to Kiss", 130, $version."_reply_to_kiss_b.gif", true );
	create_button_image( "Request Chat", 130, $version."_request_chat_b.gif", true );
	create_button_image( "Save", 80, $version."_save_b.gif", true );
	create_button_image( "Search", 100, $version."_search_b.gif", true );
	create_button_image( "Select File", 110, $version."_select_file_b.gif", true );
	create_button_image( "Send Email", 130, $version."_send_email_b.gif", true );
	create_button_image( "Send Kiss", 130, $version."_send_kiss_b.gif", true );
	create_button_image( "Send Password", 150, $version."_send_password_b.gif", true );
	create_button_image( "Send Reply", 125, $version."_send_reply_b.gif", true );
	create_button_image( "Send", 75, $version."_send_b.gif", true );
	create_button_image( "Sent", 140, $version."_sent_b.gif", true );
	create_button_image( "Set as Primary", 140, $version."_set_as_primary_b.gif", true );
	create_button_image( "Subscribe", 110, $version."_subscribe_b.gif", true );
	create_button_image( "Upload", 90, $version."_upload_b.gif", true );
	create_button_image( "View Profile", 130, $version."_view_profile_b.gif", true );
	create_button_image( "Yes", 70, $version."_yes_b.gif", true );


		/* Creates a GIF button */

		/* possible extensions: */
		/*    fade the anti-aliasing to a user-specified background rather than just black or white */
		/*    improve the text using Postscript fonts or bitmapped fonts */

	function create_button_image( $text, $width, $filename, $dark_background=false )
	{
		$pathroot = val( $_SESSION, "pathroot" );

		$destfile = $pathroot."/button_scratchpad/".$filename;

		$height = 21;
		$font_size = 12;

		$xo = 10;
		$xo2 = $width - 11;
		$yo = 10;


			/* create image and colors */

		$im = imagecreatetruecolor( $width, $height );

		if ($dark_background)
			$basecolor = imagecolorallocate( $im, 0, 0, 0 );
		else
			$basecolor = imagecolorallocate( $im, 255, 255, 255 );

		$bgcolor = imagecolorallocate( $im, 68, 172, 70 );

		$textcolor = imagecolorallocate( $im, 255, 255, 255 );

		$transparent_color = imagecolorallocate( $im, 0, 1, 0 );

		imagecolortransparent( $im, $transparent_color );


			/* color the new image transparent */

		imagefilledrectangle( $im, 0, 0, $width, $height, $transparent_color );


			/* draw the two cirles for the button ends */

		imagefilledarc( $im, $xo, $yo, $height, $height, 0, 360, $bgcolor, 0 );

		imagefilledarc( $im, $xo2, $yo, $height, $height, 0, 360, $bgcolor, 0 );


			/* antialias the circles */

		for ($x=0; $x < $xo; $x++)
		{
			for ($y=0; $y < $height; $y++)
			{
				$dist = sqrt( abs($x-$xo)*abs($x-$xo) + abs($y-$yo)*abs($y-$yo) );

				if ($dist > $height/2-0.5 && $dist < $height/2+0.5)
				{
					$adj = ($dist - ($height/2-0.5)) / (($height/2+0.5) - ($height/2-0.5));

					if ($dark_background)
						$colorx = imagecolorallocate( $im, 68 - 68*$adj, 172 - 172*$adj, 70 - 70*$adj );
					else
						$colorx = imagecolorallocate( $im, 68+(255-68)*$adj, 172+(255-172)*$adj, 70+(255-70)*$adj );

					imagesetpixel( $im, $x, $y, $colorx );
				}
			}
		}

		for ($x=$xo2; $x < $width; $x++)
		{
			for ($y=0; $y < $height; $y++)
			{
				$dist = sqrt( abs($x-$xo2)*abs($x-$xo2) + abs($y-$yo)*abs($y-$yo) );

				if ($dist > $height/2-0.5 && $dist < $height/2+0.5)
				{
					$adj = ($dist - ($height/2-0.5)) / (($height/2+0.5) - ($height/2-0.5));

					if ($dark_background)
						$colorx = imagecolorallocate( $im, 68 - 68*$adj, 172 - 172*$adj, 70 - 70*$adj );
					else
						$colorx = imagecolorallocate( $im, 68+(255-68)*$adj, 172+(255-172)*$adj, 70+(255-70)*$adj );
				
					imagesetpixel( $im, $x, $y, $colorx );
				}
			}
		}

			/* draw the center rectangle */

		imagefilledrectangle( $im, $height/2, 0, $width - $height/2, $height, $bgcolor );


			/* draw the text */

		$size = imagettfbbox( $font_size, 0, "ARIALNB.TTF", $text );

		imagettftext($im, $font_size, 0, ($width - $size[2])/2, 15, $textcolor, "ARIALNB.TTF", $text );

		imagegif( $im, $destfile, 0 );

		echo "<img src='/button_scratchpad/".$filename."'><br><br>";
	}

?>

