function createImageFromText($text,$fontSize=12,$fontColor="#FFF",$imageSize=array(300,50),$fontFamily="arial.ttf",$rotationAngle=0, $xCoordinate=20, $yCordinate=120){ header("Content-type: image/png"); //Picture Format header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // NO CACHE/*image generation code*/ //create Image of size 350px x 75px $bg = imagecreatetruecolor($imageSize[0],$imageSize[1]); //This will make it transparent imagesavealpha($bg, true); $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); imagefill($bg, 0, 0, $trans_colour); //Text to be written
// $helloworld = isset($_GET['text']) ? $_GET['text'] : "Rajan Maharjan";// White text $white = imagecolorallocate($bg, 255, 255, 255); // Grey Text $fontColor = imagecolorallocate($bg, 128, 128, 128); // Black Text $black = imagecolorallocate($bg, 0,0,0); imagettftext($bg, $fontSize, $rotationAngle, $xCoordinate, $yCoordinate=20, $fontColor, $fontFamily, $text); //Create image imagepng($bg); return imagepng($bg);
} echo createImageFromText("friendship.rajan@gmail.com",12,'',array(200,40));