undefined function: imagecreatetruecolor

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
tearaway
Forum Newbie
Posts: 1
Joined: Sun Jan 22, 2006 1:08 pm
Location: Waterford, Michigan
Contact:

undefined function: imagecreatetruecolor

Post by tearaway »

hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I am working with GD on a Unix server. Using [url]http://www.php.net/manual/en/ref.image.php[/url] as my guide I created a file called linechart.php with the code below. I uploaded the file and it worked fine. I noted among the changes I wanted to make was a brighter background to get more contrast. After some time passed and I returned to the project, running the unchanged file at [url]http://gauss.math.oakland.edu/chagas/linechart.php[/url] gives the error:

Code: Select all

<br />
<b>Fatal error</b>:  Call to undefined function:  imagecreatetruecolor() in <b>/usr/local/www/data-dist/chagas/linechart.php</b> on line <b>12</b><br />
(The error is similar if I use imagecreate)

I am new to PHP and Unix. The server administrator tells me nothing has changed on the server.

Please advise me on what steps need to be done to get this sample code running again on a Unix server.

Also, looking ahead, I'd like to use GD to creat the image embedded in a page that I have output HTML, then the image, then more HTML. Since the example uses header("Content-type: image/png"); I know I can't just nest it in an series of echo commands outputting HTML and text. Any help on the general solution for that is also appreciated.

This work is for an Oakland University research project that will allow field biologists in South America to enter in parameters defining villages and get back a predictive model of the spread of Chagas Disease based on spraying applications.

Code --------------------------------------------

Code: Select all

<?
// Add values to the graph
$graphValues=array(0,80,23,11,190,245,50,80,111,240,55);

// Define .PNG image
header("Content-type: image/png");
$imgWidth=250;
$imgHeight=250;

// Create image and define colors
//$image=imagecreate($imgWidth, $imgHeight);
$image=imagecreatetruecolor($imgWidth, $imgHeight);
$colorWhite=imagecolorallocate($image, 255, 255, 255);
$colorGrey=imagecolorallocate($image, 192, 192, 192);
$colorBlue=imagecolorallocate($image, 0, 0, 255);

// Create border around image
imageline($image, 0, 0, 0, 250, $colorGrey);
imageline($image, 0, 0, 250, 0, $colorGrey);
imageline($image, 249, 0, 249, 249, $colorGrey);
imageline($image, 0, 249, 249, 249, $colorGrey);

// Create grid
for ($i=1; $i<11; $i++){
imageline($image, $i*25, 0, $i*25, 250, $colorGrey);
imageline($image, 0, $i*25, 250, $i*25, $colorGrey);
}

// Create line graph
for ($i=0; $i<10; $i++){
imageline($image, $i*25, (250-$graphValues[$i]), ($i+1)*25, (250-$graphValues[$i+1]), $colorBlue);
}

// Output graph and clear image from memory
imagepng($image);
imagedestroy($image);

?>
hawleyjr | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Please use PHP tags
Coming to the problem, I did not read all of the post.........

Code: Select all

b>Fatal error</b>: Call to undefined function: imagecreatetruecolor() in <b>/usr/local/www/data-dist/chagas/linechart.php</b> on line <b>12</b><br />

I do not see any file includes in your code....include the file where those image functions are located.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

raghavan20 wrote:Please use PHP tags
Coming to the problem, I did not read all of the post.........

Code: Select all

b>Fatal error</b>: Call to undefined function: imagecreatetruecolor() in <b>/usr/local/www/data-dist/chagas/linechart.php</b> on line <b>12</b><br />

I do not see any file includes in your code....include the file where those image functions are located.
imagecreatetruecolor is a php function

http://us2.php.net/manual/en/function.i ... ecolor.php

use phpinfo() to determine if GD is installed.
Post Reply