I have been playing around with generating images using php. The end goal is produce graphs generated from data pulled from a MySQL database. I will post more later but here are some of the problems that I have resolved so far:

Unable to generate an image or getting an error like:

The image “http://localhost/button.php” cannot be displayed, because it contains errors.
The cause of the problem wasn’t a wrongly installed GD or anything. Look at the file you are using and look for a line like $font = ‘arial.ttf’; It seems that later versions of php (Possibly, I don’t know for a fact), e.g. 5+ require the FULL location of the file, not a relative location. So the line must read something like:

$font = ‘/use/share/fonts/arial.ttf’; (I have made this up, check for your distro)

The second problem I was having was when I finally created the image, how do I incorporate the image into a page? I tried using include(‘button.php’) but it failed with:Warning: Cannot modify header information – headers already sent

The problem is that the page calling the button.php script has already set the header as text/html and this can’t be modified. Images CAN be incorporated by not by include(), the trick is remembering you are trying to insert an image and should therefore use the syntax for inserting an image, not the syntax for a script. Therefore use: