Page 1 of 1

GD question

Posted: Mon Oct 20, 2003 10:44 pm
by maniac9
I've followed some links given here and gotten GD stuff to work - at least I thought...

this page - http://public.radicant.net/motr_keystrokes.php - works when viewed by itself, but it doesn't when i try to include it as an image in html...here's the code

PHP -

Code: Select all

<?php

	// open stats file
	$file = fopen("http://pulse.whatnet.org/api/user.php?account=motr", "r");

	// skip to number file
	fgets($file);
	fgets($file);
	fgets($file);
	fgets($file);
	fgets($file);
	fgets($file);
	fgets($file);
	fgets($file);
	$Keystrokes = explode(" ", fgets($file));

	// close stats file
	fclose($file);

	// create image
	header ("Content-type: image/png");
	$img_handle = ImageCreate (220, 18) or die ("Cannot Create image");
	$back_color = ImageColorAllocate ($img_handle, 67, 64, 58);
	ImageTTFText ($img_handle, 8, 0, 5, 12, ImageColorAllocate ($img_handle, 143, 137, 127), "/WINDOWS/Fonts/Verdana.ttf",  $Keystrokes[2] . " keystrokes and counting...");
	ImagePng ($img_handle);
	
?>
HTML -

Code: Select all

<img src="http://public.radicant.net/motr_keystrokes.php" alt="" />
Any ideas?

Posted: Fri Oct 24, 2003 7:57 am
by maniac9
any ideas?

Posted: Fri Oct 24, 2003 8:47 am
by volka
Do you have any! output in that script before header ("Content-type: image/png"); ? It seems like the script is not able to set the content-type, it ships as text/html (the default).
What happens if you try

Code: Select all

<?php
   error_reporting(E_ALL);
   ini_set('display_errors', TRUE);
   // open stats file
   $file = fopen("http://pulse.whatnet.org/api/user.php?account=motr", "r"); 
...

Posted: Fri Oct 24, 2003 8:54 am
by maniac9
That seemed to change something - the image seemed to load faster by itself (at least it seemed that way) - but it still won't load inside any html, it just displays a good ol' X

is there something i'm just doing wrong?

Posted: Fri Oct 24, 2003 9:28 am
by volka
what does the complete script look like?
if <?php is the beginning, what's the linenumber?

Posted: Fri Oct 24, 2003 11:37 am
by maniac9
that is the complete script - left out the last ?> by accident

Posted: Fri Oct 24, 2003 12:07 pm
by volka
and <?php is really in the first line, no blank line, no space, nothing before it in the file?
I've tested the script here, works fine for me

Posted: Fri Oct 24, 2003 12:12 pm
by maniac9
nope, nothing before it...maybe something to do with apache?

Posted: Fri Oct 24, 2003 5:49 pm
by volka
hm, something that prevents php from sending the content-type....
is php installed as module or cgi (and btw: which version is it?)?
any auto_prepend_file directive?

...not much I can think of ;)

Posted: Fri Oct 24, 2003 5:55 pm
by maniac9
right now its installed on apache as a module - version 4.3.3 with the latest version of apache

I think im going to try it on IIS in a bit, see if I get some other kind of result

Posted: Fri Oct 24, 2003 6:41 pm
by JAM
The above worked locally at home, and at one of my hosts. I had some problems on a third host, but found that spaces in the path to the .ttf was making it fubar, so bypassing it using dirname(__FILE__) I did...

http://phpdn.jam.nu/GDWhatpulse/ (working incl. source)
Image

Not sure this is what causes your problem, but... Worth mentioning.