954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Image processing

hello everyone..
i would to ask about my simple code here.. it's not working..
i actually want to display a forum badge which is data are received from the database. And i stucked at putting the avatar to a portion of the badge..i mean it looks like facebook profile badge...
i created a background image using imagecreatefrompng() function..

can anybdy with this?

<?php

	define('PUN_ROOT', '../');
	require PUN_ROOT.'include/common.php';

	$id = isset($_GET['id']) ? base64_decode($_GET['id']) : 0;

	//PHP's GD class functions can create a variety of output image
	//types, this example creates a jpeg
	header("Content-type: image/png");

	//open up the image you want to put text over
	$im = imagecreatefrompng("testing.png");

	//The numbers are the RGB values of the color you want to use
	$black = imagecolorallocate($im, 0, 51, 102);


	$sql = $db->query('SELECT username, num_posts FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch new password', __FILE__, __LINE__, $db->error());
	$result = $db->fetch_assoc($sql);
	$Uname = $result['username'];
	$Nopost = 'No. of posts&raquo; '.$result['num_posts'];
	
	//font
	$font = './Verdana.ttf';
	
	//write data to the image	
	imagettftext($im, 10, 0, 20, 12, $black, $font, $Uname);
	imagettftext($im, 10, 0, 20, 30, $black, $font, $Nopost);
	
	//path to avatar directory
	$avapath = '../img/avatars/'.$id.'png';
	
	// Copy and merge avatar to the backgroud
	// Something wrong here.. =(
	$src = imagecreatefrompng($avapath);
	imagecopymerge($im, $src, 10, 10, 0, 0, 100, 47, 75);
    
	imagepng($im);
	imagedestroy($im); 

?>
lili.edryana
Light Poster
47 posts since Nov 2009
Reputation Points: 10
Solved Threads: 2
 

Hey.

Try commenting out the header and see if you get any errors. (Line #10).
You might have to turn on error reporting to see them, by adding this to the top of the script:

ini_set('display_errors', true);
error_reporting(E_ALL);


I tried you code on my test server and it seems to work fine, so this is most likely something minor, like a broken path to an image. The errors will tell us exactly what it is.

P.S.
Line #22. 'No. of posts&raquo; ' . There should not be a HTML entity in that, as this text is not going to be printed to a HTML page. You should be using the real symbol: 'No. of postsĀ» '

Atli
Posting Pro
540 posts since May 2007
Reputation Points: 93
Solved Threads: 70
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You