Page 1 of 1

dynamic image generation, problems

Posted: Wed Nov 22, 2006 10:34 pm
by mckooter
First off, im not a php coder, im working on it, so I took all the info I am shown below from two different scripts online and tried to make them work together, so far no luck

I am trying to make a dynamic signature that shows the status of a server online, but it is not working, these are my scripts (with websites removed) And i have installed the script to my .htaccess to rewrite the png to php

status2.png

Code: Select all

<?php
Header("Content-type: image/png");
//***************
//The status checking script
//meddle at your own risk!
//check for port number, default is 80
$addr = "mckooter.com";
$port = 80;

//Test the server connection
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);
             if (!$churl){
			 //echo $errstr;
               $onoff = "online.gif";
                }
             else {
             	 $onoff = "offline.gif";             
		  }


include('status2p.php');		  

?>

status2p.php

Code: Select all

<?php
header("Content-type: image/png");

$im = imagecreatefromgif($onoff);		  

imagepng($im);
imagedestroy($im);

?>

it just shows me the image path as the image, firefox is now recognizing it as an image so i know ive got further, any help would be greatly appreciated

Posted: Thu Nov 23, 2006 12:09 am
by volka
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 20);
What a function is server()?
Just for debugging purposes try it without the @ and remove the Header("Content-type: image/png"); in status2.png. Then call the script directly (not as <img src=... )

Posted: Thu Nov 23, 2006 8:30 pm
by mckooter
tried that, nothing, now firefox dosent recognize its an image anymore...

hmmm... messed something up i can see

Posted: Thu Nov 23, 2006 11:00 pm
by volka

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);

$addr = "mckooter.com";
$port = 80;

$churl = fsockopen(server($addr), $port, $errno, $errstr, 20);
if (!$churl) {
	$onoff = "online.gif";
}
else {
	$onoff = "offline.gif";             
}

$im = imagecreatefromgif($onoff);

if ( !headers_sent() ) {
	header("Content-type: image/png");
	imagepng($im);
}
?>

Posted: Thu Nov 23, 2006 11:23 pm
by mckooter
stupid me, you mentioned it in your first post, i missed a critical part, and showing the errors solved it

Code: Select all

function server($addr){
         if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
         return $addr;
}
i appologise my idiocy, i just didnt understand what you meant in your first post...

without that the server($addr) function dosent exist, added and it works great!, thanks so much

one last question though, can you make a gif file using those commands? maybe imagegif($im) and if so does it pose any problems, all the dyanmic image things i have seen use png, but those are using text as well,


thanks!

Posted: Thu Nov 23, 2006 11:45 pm
by volka
http://de2.php.net/image wrote:imagegif -- Output image to browser or file
But if you already have gif files you only need to deliver the data without the need (/time/memory consumption) of the gd extension

Code: Select all

if ( !headers_sent() ) {
	header('Content-type: image/gif');
	readfile($onoff);
}

Posted: Thu Nov 23, 2006 11:48 pm
by mckooter
thanks so much, wish there was a thanks button so i could show how much help you have been


now it works, now for added features xml integration, (ill read a ton before attempting this)

Posted: Fri Nov 24, 2006 3:42 am
by onion2k
volka wrote:
http://de2.php.net/image wrote:imagegif -- Output image to browser or file
But if you already have gif files you only need to deliver the data without the need (/time/memory consumption) of the gd extension

Code: Select all

if ( !headers_sent() ) {
	header('Content-type: image/gif');
	readfile($onoff);
}
He's not sending a gif, he's sending a PNG. I guess there's a reason for the conversion.