GD question

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
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

GD question

Post 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?
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

any ideas?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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"); 
...
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what does the complete script look like?
if <?php is the beginning, what's the linenumber?
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

that is the complete script - left out the last ?> by accident
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post by maniac9 »

nope, nothing before it...maybe something to do with apache?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
maniac9
Forum Commoner
Posts: 55
Joined: Fri Aug 01, 2003 12:27 am
Location: Arkansas, USA
Contact:

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply