Author Topic: Trouble with PHP and a gif image  (Read 2573 times)

0 Members and 1 Guest are viewing this topic.

Offline Arthurhh

  • Senior Contributor
  • ****
  • Posts: 266
  • IT Fixer
    • Tokoroa Weather Live
Trouble with PHP and a gif image
« on: July 04, 2008, 03:45:29 AM »
My output is here

http://tokoroaweatherlive.dyndns.org:8080/test.php

I am using Slo weather FWI Script as a PHP include in a carter lake page, but I am having problems getting the image to display.
fwi.php displays fine but all I get is the GIF image file contents when I include it in a carter lake page

Any hints? Google has not proved to be my friend

Offline SLOweather

  • Global Moderator
  • Forecaster
  • *****
  • Posts: 3456
    • Weatherelement Moline IL
Re: Trouble with PHP and a gif image
« Reply #1 on: July 04, 2008, 01:43:57 PM »
Could you post the link to the script itself, as well as the code snippet plus a few lines on each side where you are including it in the page?

Chris

Offline Arthurhh

  • Senior Contributor
  • ****
  • Posts: 266
  • IT Fixer
    • Tokoroa Weather Live
Re: Trouble with PHP and a gif image
« Reply #2 on: July 04, 2008, 07:40:33 PM »
I have resorted to including the entire fwi.php file in the cater lake template page. But that still does not get me past it.
On the site the original page works and displays the gif fine but as soon as it is in carter lake template in fails and just shows the text of the file.

The fwi.php file works file http://tokoroaweatherlive.dyndns.org/fwi.php
The file I want it to display in http://tokoroaweatherlive.dyndns.org/wxfwi.php

Below is the content of my body section of the code

Code: [Select]
<body>
<?php
############################################################################
include("header.php");
############################################################################
include("menubar.php");
############################################################################
?>


<!--start main content-->
<div id="main-copy">

 <?php

// Based on firedanger script by SLOweather.com, modified to use Weather
// Display clientraw.txt data file. Release 08/25/07 by W7RSW
// Initial release 070625 (YYMMDD) by SLOweather.com
// This script uses temperature in F and relative Humidity to
// calculate the Chandler Burning index and then select the
// appropriate graphic to display. It also selects the proper
// adjective for the current conditions, but this feature is not
// currently used for anything.

// As written, it requires an image pack of 5 graphics for each of
// the 5 danger levels, in the same directory as the script.

// Based on data from Anole's stickertags.txt file.
// For more information on the Chandler Burning Index:
// http://www.fs.fed.us/psw/topics/fire_science/fire_weather/mfwf/MFWFDesc.shtml
// For the Adjective Fire Danger text for each CBI level
// http://famweb.nwcg.gov/pocketcards/adjective.htm

// DATA FILE: defines the path to the data file.
// The path can be absolute or relative or a URL)!!

$data_file_path  'clientraw.txt';
// get the data file
$dataraw file_get_contents($data_file_path);


// see if the data file is a WD clientraw.txt file and set
// the WD flag for those specific routines to be executed.
if (preg_match('|clientraw.txt|'$data_file_path)){
   
$use_wd_clientraw '1';
//end if

// clean up any blank lines
$dataraw trim($dataraw);
$dataraw preg_replace("/[\r\n]+[\s\t]*[\r\n]+/","\n",$dataraw);

// if we're using the WD clientraw.txt we have a lot of work to do to make it
// pretty. So here we go:

// put the clientraw.txt data into an array and define the data points
if ($use_wd_clientraw == '1') {
   
$data explode(" "$dataraw);
   
// clean up and define


   
(float)$cTemp "$data[4]";
   (float)
$rh "$data[5]";

   function 
tempToFahrenheit ($cTemp$prec=0)
// Given a temperature in degrees Fahrenheit, convert it
// to Celsius and return the value.  Use an integer for
// precision ($prec) to round the converted value.
// Returns FALSE on error.
{
  if (!isset(
$cTemp)) {
    return 
false;
  }
  
$prec = (integer)$prec;
  
$fTemp = (float)(1.8 $cTemp) + 32;
  return 
round($fTemp$prec);
}

$ftemp tempToFahrenheit ($cTemp);


// Start Index Calcs

// Chandler Index
$cbi = (((110 1.373 $rh) - 0.54 * (10.20 $cTemp)) * (124 pow(10,(-0.0142*"$rh"))))/60;
// CBI = (((110 - 1.373*RH) - 0.54 * (10.20 - T)) * (124 * 10**(-0.0142*RH)))/60

//Sort out the Chandler Index


if ($cbi "97.5") {
    
$cbitxt "EXTREME";
    
$cbiimg"fdl_extreme.gif";

} elseif (
$cbi >="90") {
    
$cbitxt "VERY HIGH";
    
$cbiimg"fdl_vhigh.gif";

} elseif (
$cbi >= "75") {
    
$cbitxt "HIGH";
    
$cbiimg"fdl_high.gif";

} elseif (
$cbi >= "50") {
    
$cbitxt "MODERATE";
    
$cbiimg"fdl_moderate.gif";

} else

if (
$cbi "50") {
    
$cbitxt="LOW";
    
$cbiimg"fdl_low.gif";

}


$img imagecreatefromgif($cbiimg);
// additions by Saratoga-Weather.org
  
$degree_units '°C';
  
$color_red imagecolorallocate($img,255,0,0);      // RED
  
$color_green imagecolorallocate($img,0,128,0);      // GREEN

// If Celsius units desired, use
 
$ntemp round($cTemp,1);
//  $ntemp = round($ftemp,1);
  
$nrh round($rh,0);
  
$ncbi round($cbi,0);

  
imagestring($img290116"$ntemp$degree_units"$color_green);
  
imagestring($img2130116"$nrh%"$color_green);
  
imagestring($img298127"CBI: $ncbi"$color_red);

// ---------------------------------
//header("Content-type: image/gif");    //defined in ajax-gizmo
imageGIF($img);
imagedestroy($img);

}





</
div>

<!-- 
end main-copy -->

Offline Arthurhh

  • Senior Contributor
  • ****
  • Posts: 266
  • IT Fixer
    • Tokoroa Weather Live
Re: Trouble with PHP and a gif image
« Reply #3 on: July 05, 2008, 12:54:22 AM »
Got it didnt have a deep enough understanding (probably still havnt) but
calling the fwi.php by <img src="fwi.php" alt="Fire Warning Index" /> in my wxfwi page results in the correct result

 

anything