PHP GD, How do i use include or require?

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
Shadowrider50
Forum Newbie
Posts: 5
Joined: Sat Jan 28, 2012 3:00 am

PHP GD, How do i use include or require?

Post by Shadowrider50 »

I am trying to use the function include (or require) in a php gd image but
the image i create in php gd says "The image contains errors" whenever i try to use the "include" or "require" function?

It works without those 2 functions but if i try to use those it gives error.
The file i am including using include/require contains no errors itself so that is not the problem.

How do you use either of these 2 functions in a php gd image?

I need them because the file i am including has a set of variables being called and returned by cURL that will be used for displaying on the image.
It's for Playstation Network Trophy statistics if anyone was wondering :wink:
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP GD, How do i use include or require?

Post by social_experiment »

Code: Select all

<?php
include_once 'page.php';
    
	header('Content-type: image/png');
	$image = imagecreate(70, 18);
	$blue = imagecolorallocate($image, 255, 255, 255);
	/*
	bool imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color )
	*/
	$textCol = imagecolorallocate($image, 0, 0, 0);
	$text = $val . ' + ' . $val2;
	//$font = imageloadfont('arial.ttf');	
	$imageString = imagestring($image, 5, 0, 3, $text, $textCol);	
	imagepng($image);
	imagedestroy($image);
?>
And 'page.php' has this

Code: Select all

<?php
 $val = 5;
 $val2 = 5;
?>
It could be a problem with the data on your page that is returning the error; please paste your code
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply