I'm trying to create and display an image using php. The code I am using is shown below.
<?php
include("dbAccess.php");
$Text=getTextForID($id);
if ($Text==""){$Test="Boo";}
$png = ImageCreate(200, 80);
$bg = ImageColorAllocate($png, 255, 255, 255);
$tx = ImageColorAllocate($png, 0, 0, 0);
ImageFilledRectangle($png, 0, 0, 200, 80, $bg);
ImageString($png, 5, 45, 25, $Text, $tx);
header("content-type: image/png");
ImagePng($png);
imagedestroy ($png);
?>
It works if the first two lines are removed (getTextForID is a function in dbAccess that returns a string) as in, it displays an image, but if the first two lines are there it falls over saying:
"Warning: Cannot add header information - headers already sent by (output started at /home/xxx/public_html/list/dbAccess.php:157) in /home/xxx/public_html/list/image.php on line 13"
dbAccess contains only functions. ie there is no code executed outside of a function call. I need to get data from the db, and don't wish to move the db connection and access code out of the dbAccess file.
What is the trick on this one ?
Thanks,
Mike