Archive for the ‘PHP’ Category

Text to image in PHP

Monday, October 15th, 2007

want to show some cool font rendered as image to the client
here is sample code of how you can using GD in PHP
save the below code as text2image.php

==========text2image.php============
<?
$text=stripslashes($to_image);
$text=ucwords($text);
$temp_color=$color;
$r= hexdec( substr($temp_color,0,2));
$g=hexdec( substr($temp_color,2,2));
$b=hexdec( substr($temp_color,4,2));
header(”Content-type: image/png”);
$fonte=”path_to_font_dir/”.$font.”.ttf”;
$bbox = imagettfbbox($size,0,$fonte,$text);
$x_size = abs($bbox[4] - $bbox[0]);
$y_size = abs($bbox[5] - $bbox[1]);
$width=$x_size+5 ;
$im = imagecreatetruecolor($width, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$red=imagecolorallocate($im,$r,$g,$b);
//$string = “This is some text..”;
imagealphablending($im,true);
imagefill($im,0,0,$white);
imagettftext($im,$size/75*72, 0, 5, 21, $red, $fonte, $text);
imagepng($im);
imagedestroy($im);
?>

not from any HTML page or PHP page simple
call
<img src=”text2image.php?font=SomeFontAvailableInServer&to_image=text to display&color=ff0000″ alt=”image rendered at server”>

AMFPHP and actionscript 3

Saturday, October 13th, 2007

I am writing an online multiplayer card game that uses AMFPHP and Flash actionscript 9. Here goes the code that connects Actionscript 3 with AMFPHP. I am writing it step wise so that it may help beginners.
1) Step no 1
develop a service class in PHP and place the class at the services folder of the AMFPHP
my code goes here

=======games/Gameservice.php========
class GameService

{
function getVersion()

{
return “1.1″;
}

function getArrayWithParameter($a,$b)
{
$arr=array();
$arr[0]=$a;
$arr[1]=$b;
$arr[2]=$a+$b;
return $arr;
}

}

2) Step no 2 In action script 3
var conn:NetConnection=new NetConnection();
var resultArray:Array;
var responder:Responder=new Responder(onResult,onError);
function onResult(arr:Array)
{
resultArray=arr;

test();

}

function onError(err:Error)
{
trace(err.description);
}
conn.connect(”http://localhost/amfphp/gateway.php”);
conn.call(”games.Gameservice.getArrayWithParameter”,responder,12,122);
//here 12 and 122 are the arguments

function test()

{

trace(resultArray[3]);

//output is 134

}
}

cravewood.com

Thursday, September 20th, 2007

I wish to make a shopping site and i got a domain cravewood.com from my fren Rupesh
I have started the basic design today here is the header of the page
i wish to complete this project and give a good lunch after this Dashin holidays
wish i could ……………….