text on image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

text on image

Post 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');
?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For debugging, turn off the content-type header output.

Are you sure the font can be found?
kpraman
Forum Contributor
Posts: 172
Joined: Fri Oct 13, 2006 10:54 am

Post by kpraman »

Thanks for replying. Solved after i gave full path of .ttf
Post Reply