Hi,
I'm fairly new to php and gd, but I have created some graphs that take data from mysql and display it with a png. However, I'm now trying to use php and gd on a windows IIS server(other times have been using linux), and I'm now getting weird symbols when trying to display an image.
// Create image and define colors
$image=imagecreate($imgWidth, $imgHeight)
or die("Cannot Initialize new GD image stream");
$red = imagecolorallocate ($image, 255, 0, 0);
$link = mysql_connect('localhost', 'root', '*daver*') or die ("Could not connect: " . mysql_error());
mysql_selectdb('test',$link) or die ("Can\'t use dbmapserver : " . mysql_error());
$tslilt0 = mysql_query("select summer_am_models.fcli_sve, summer_am_models.date, summer_pm_work.date_time from summer_am_models, summer_pm_work
where day(summer_am_models.date)=day(summer_pm_work.date_time) and summer_pm_work.tsn='TS' and summer_am_models.fcli_sve<0",$link);
if (!$tslilt0)
{
echo "no results ";
}
$tsligt0 = mysql_query("select summer_am_models.fcli_sve, summer_am_models.date, summer_pm_work.date_time from summer_am_models, summer_pm_work
where day(summer_am_models.date)=day(summer_pm_work.date_time) and summer_pm_work.tsn='NOCU' and summer_am_models.fcli_sve<0",$link);
if (!$tsligt0)
{
echo "no results ";
}
I've installed php_g2.dll in my extensions directory and it seems to be working correctly based on the test array output. I've tried other random imagestrings and I get the same weird symbols. Thanks for any help!
Shad
Uncomment the header for the content type. That should fix it.
Oh, and one other comment. This relies on output buffering to be controlled by the server. If you don't get an image (which may happen if you switch servers), control it and capture it with an output buffering technique. Until that time, don't worry about it
I forgot to uncomment the header before I sent the post...but when I uncomment it, all I get is a box with a red x. I even put a simple imageline as follows just to test in case something with the mysql data is wrong.
imageline($image, 0, 600, 800, 600, $red);
If thats from including the image in an actual <img> tag, the problem may be because you are not flushing / using your output buffer.
Remember as well, since this is an image use absolutly NO output to the browser. Disable your error reporting (or even better, log it in a file instead), and remove all the echo's present. Now, before you run the imagepng, try to buffer it instead:
PHP Code:
$output = ""; ob_start(); imagepng($image); // Remember, get rid of your var dump as well. $output = ob_get_contents(); ob_end_clean(); print $output;
'Course, you can always flush it instead, but with the variables there you can kind of see what that does.
Try that out, see if its a problem with the buffering instead of the header.
If your script used to work, and now it doesn't, I'd put buffering as a high cause for many many php issues.
sorry, no luck. still the red x box, and I added your suggested code. Is this odd cosidering when I run phpinfo I see that png is enabled? Any other thoughts? Thanks for your time,
Yeah, cheezy image base. But it worked without a problem. The only real changes from your code are:
- removed any mysql functions
- Added white so I could add it to the original background. Not really necessary but still...
- Changed the subtraction base to just be a random number between 75 & 150
- Added the ob_handler function. This just lets me get away with controlling the output as an image. Could be handy if you wanted to do error reporting instead, but will fail in an <img> tag...
- Flushed the buffer instead of capturing the outputs.
So I'm not sure what the problem is exactly. Like I said, you're almost there, so just keep tweeking it and eventually you'll get it to go
Also, keep in mind you may need to clear your browser's cache out, it may be trying to give a bad image that was previously loaded up.
Good luck mate, keep trying the little things, you're almost done!