Page 1 of 1

text on image

Posted: Wed Mar 28, 2007 11:31 pm
by kpraman

Code: Select all

<?php
    function image($sizeinp,$text,$textdb,$font)
	{
	    $size = imagettfbbox($sizeinp, 0, $font, $text);
		$xsize = abs($size[0]) + abs($size[2]);
		$ysize = abs($size[5]) + abs($size[1]);
	
		$image = imagecreatefromjpeg("textimage.jpg");
		$imagesize = getimagesize("textimage.jpg");
		$textleftpos = round(($imagesize[0] - $xsize) / 2);
		$texttoppos = round(($imagesize[1] + $ysize) / 2);
		$white = ImageColorAllocate($image, 229,232,213);
	
	 	chmod("textimage.jpg",0777);
		imagettftext($image, $sizeinp, 0, $textleftpos, $texttoppos, $white, $font, $text);
		imagejpeg($image,"image/$textdb".".jpg");
		
   }
?>
The above function writes text on the image. It also renames the image name and saves in image folder. It works fine in my local system. but, when i upload to online server. It is not writing on the image.

calling the function:

Code: Select all

<?php
image('31',$cat_Name,$catdb,'alsscrp.ttf');
?>

Posted: Thu Mar 29, 2007 3:24 am
by s.dot
is $cat_Name a valid value?
are there any errors? (turn display errors on)
does the system have gd installed and the freetype library configured?

Posted: Thu Mar 29, 2007 7:36 am
by kpraman
It is enabled.

I tried,

Code: Select all

<?php
header("Content-type: image/png");
$im = @imagecreate(500, 500)
    or die("Cannot Initialize new GD image stream");
	
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 20, 5, 5,  "A Simple Text String", $text_color);
imagettftext($im, 20, 0, 40, 60, $text_color, 'alsscrp.ttf', 'this is testing');
imagepng($im);
imagedestroy($im);

?>

Code: Select all

imagestring($im, 20, 5, 5,  "A Simple Text String", $text_color);
works fine

Code: Select all

imagettftext($im, 20, 0, 40, 60, $text_color, 'alsscrp.ttf', 'this is testing');
does not work in online

Posted: Thu Mar 29, 2007 9:43 am
by feyd
For debugging, turn off the content-type header output.

Are you sure the font can be found?

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