Page 1 of 1

Writing text on image

Posted: Fri Mar 16, 2007 4:58 am
by kpraman

Code: Select all

<?php
    if(!isset($_GET['size'])) $_GET['size'] = 26;
    if(!isset($_GET['text'])) $_GET['text'] = "Hello";

    $size = imagettfbbox($_GET['size'], 0, "ARIAL", $_GET['text']);
    $xsize = abs($size[0]) + abs($size[2]);
    $ysize = abs($size[5]) + abs($size[1]);

    $image = imagecreatefromjpeg("3_1.jpg");
    $imagesize = getimagesize("3_1.jpg");
    $textleftpos = round(($imagesize[0] - $xsize) / 2);
    $texttoppos = round(($imagesize[1] + $ysize) / 2);
    $white = ImageColorAllocate($image, 255,255,255);

    imagettftext($image, $_GET['size'], 45, $textleftpos, $texttoppos, $white, "ARIAL", $_GET['text']);
    header("content-type: image/png");
    $img=imagejpeg($image);
    imagedestroy($image);
	
	
 
echo "<img src= $img >";

?>
WIth the above script i am able to write text on an image. How can i change font style(bold,italic..)?

Posted: Thu Mar 29, 2007 10:25 am
by Benjamin
research the imagettftext function

Posted: Thu Mar 29, 2007 10:50 am
by anjanesh
Also try imagestring

Posted: Fri Mar 30, 2007 5:03 am
by kpraman
Thanks for replying. Solved after i gave full path of .ttf