Help me ASAP - images error

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
kumarangopi
Forum Newbie
Posts: 10
Joined: Wed Oct 18, 2006 7:43 am

Help me ASAP - images error

Post by kumarangopi »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


1) Environment : Red Hat Linux 5.x
2) PHP version 2.x
3) Apache
4) I have used xampp for installing php and apache
5)example.php

Code: Select all

<?php
 include('GrowthChart.class.php');
 $patientXData = array(2,  4,  6,  8, 10, 12);
 $patientYData = array(36, 40, 42.2, 44, 45, 45.8 );
 $xvals = join(',', $patientXData);
 $yvals = join(',', $patientYData);
 
?>
<html>
<head>
 <title>Growth Chart Example</title>
</head>
<body>
 <img src="chart.php?style=<?= GrowthChart::STYLE_HEAD_AGE ?>&sex=<?= GrowthChart::SEX_MALE ?>&maxage=35&xvals=<?= $xvals ?>&yvals=<?= $yvals ?>" />
</body>
</html>
chart.php:

Code: Select all

<?php
include_once('GrowthChart.class.php');
import_request_variables('g', 'url_');
$style = null;
$sex = null;
$maxage = null;
$width = null;
$height = null;
// check for minimum required variables
if (!isset($url_style) || !isset($url_sex) || !isset($url_maxage))
{
 die('One or more expected request variables not present.');
}
// check style value
if (!is_numeric($url_style) || (int)$url_style < 0 || (int)$url_style > 5)
{
 die('Style value out of range: ' . $url_style);
}
$style = $url_style;
// check sex value
if (!is_numeric($url_sex) || $url_sex < 1 || $url_sex > 2)
{
 die('Sex value out of range: ' . $url_sex);
}
$sex = $url_sex;
// check maximum age value
if (!is_numeric($url_maxage) || $url_maxage < 0)
{
 die('Maximum age value out of range: ' . $url_maxage);
}
$maxage = $url_maxage;
// check image width
if (isset($url_width) && !is_numeric($url_width))
{
 die('Image width value out of range: ' . $url_width);
}
$width = (isset($url_width) ? $url_width : 800);
// check image height
if (isset($url_height) && !is_numeric($url_height))
{
 die('Image height value out of range: ' . $url_height);
}
$height = (isset($url_height) ? $url_height : 800);

$patientXarray = null;
$patientYarray = null;
// check patient data values
// expecting comma-separated lists of x coordinates and y coordinates
if (isset($url_xvals) && isset($url_yvals))
{
 $paX = split(',', $url_xvals);
 $paY = split(',', $url_yvals);
 
 if (sizeof($paX) == sizeof($paY))
 {
  $okay = true;
  foreach ($paX as $value)
  {
   if (!is_numeric($value))
    $okay = false;
  }
  
  foreach ($paY as $value)
  {
   if (!is_numeric($value))
    $okay = false;
  }
  
  if ($okay)
  {
   $patientXarray = $paX;
   $patientYarray = $paY;
  }
 }
}

$chart = new GrowthChart($style, $sex, $maxage, $width, $height, $patientXarray, $patientYarray);
$chart->render();
?>
This my text.When Iam running example.php, Iam getting erorr 'image cannot be displayed,since it contains errors' can you pls help me pls.I have check output buffering in s/opt/lampp/etc/php.ini, it is off.I removed space after last line in example,chart,growthchart.class,jpgraph,jpgraph-line,jpgraph-restat php files

Please Kindly help me ASAP


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Usually, when you post code for us to help you with, you should have already done a good amount of debugging yourself and know pretty much where the problem lies. It doesn't sound like you have, and you just assumed that your code was right. Anything could have gone wrong from your variable validation to the creation of your arrays.

You aren't giving us much. From the sound of things, the error message is generated by $chart->render(). Have you looked at the class' code? I'm sure there's something that you are missing. Maybe your array isn't formatted correctly.

And just a small suggestion, in your foreach loops, after setting $okay=false, you should break.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Maybe your headers aren't being sent properly?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

It's a GD problem. Open up GrowthChart.class.php, find the bit that outputs the Content-Type header and the image data, comment them both out, and then load the image in a browser. That will tell you what the problem is.
Post Reply