dynamic image generation, problems

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
mckooter
Forum Commoner
Posts: 26
Joined: Fri Jul 28, 2006 10:02 pm

dynamic image generation, problems

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

Post 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=... )
mckooter
Forum Commoner
Posts: 26
Joined: Fri Jul 28, 2006 10:02 pm

Post by mckooter »

tried that, nothing, now firefox dosent recognize its an image anymore...

hmmm... messed something up i can see
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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);
}
?>
mckooter
Forum Commoner
Posts: 26
Joined: Fri Jul 28, 2006 10:02 pm

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

Post 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);
}
mckooter
Forum Commoner
Posts: 26
Joined: Fri Jul 28, 2006 10:02 pm

Post 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)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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