Jump to content

GD not working


AV1611

Recommended Posts

I have a nice pie chart script but it doesn't seem to be working correctly on some servers. The script is below.

 

I have 4 Servers, 3 are Fedora 10 with LAMP and GD enabled, and 1 is Mint Linux (Ubuntu/Debian) with LAMP and GD.

 

The Script works on the Mint Linux setup at http://64.234.49.7/new.php

 

The same Script is at http://69.59.125.225/stripe/new.php but doesn't work.

 

I get no errors, and GD does work both on other scripts and the output to screen isn't text, it's a JPEG image...

 

I'm very confused and can't imagine what to look at to figure out the issue.  Like I said, GD does work on other scripts I use on the Fedora server.

 

Here is the script:

 

<?php

$show_label = true; // true = show label, false = don't show label.

$show_percent = true; // true = show percentage, false = don't show percentage.

$show_text = true; // true = show text, false = don't show text.

$show_parts = false; // true = show parts, false = don't show parts.

$label_form = 'square'; // 'square' or 'round' label.

$width = 199;

$background_color = 'bbccdd'; // background-color of the chart...

$text_color = '000000'; // text-color.

$colors = array(

'520000',

'00c309',

'9f1951',

'198ff6',

'75199f',

'aa0505',

'9f7519',

'199f99',

'194d9f',

'BFBFC1'

 

); // colors of the slices.

$shadow_height = 16; // Height on shadown.

$shadow_dark = true; // true = darker shadow, false = lighter shadow...

 

// DON'T CHANGE ANYTHING BELOW THIS LINE...

 

//$data = $_GET["data"];

//$label = $_GET["label"];

$data='10*20*5*10*55';

$label='Cows*Lizards*Fish*Snakes*Frogs';

 

 

 

$height = $width/2;

$data = explode('*',$data);

 

if ($label != '') $label = explode('*',$label);

 

for ($i = 0; $i < count($label); $i++)

{

if ($data[$i]/array_sum($data) < 0.1) $number[$i] = ' '.number_format(($data[$i]/array_sum($data))*100,1,'.','.').'%';

else $number[$i] = number_format(($data[$i]/array_sum($data))*100,1,'.','.').'%';

if (strlen($label[$i]) > $text_length) $text_length = strlen($label[$i]);

}

 

if (is_array($label))

{

$antal_label = count($label);

$xtra = (5+15*$antal_label)-($height+ceil($shadow_height));

if ($xtra > 0) $xtra_height = (5+15*$antal_label)-($height+ceil($shadow_height));

 

$xtra_width = 5;

if ($show_label) $xtra_width += 20;

if ($show_percent) $xtra_width += 45;

if ($show_text) $xtra_width += $text_length*8;

if ($show_parts) $xtra_width += 35;

}

 

$img = ImageCreateTrueColor($width+$xtra_width, $height+ceil($shadow_height)+$xtra_height);

 

ImageFill($img, 0, 0, colorHex($img, $background_color));

 

foreach ($colors as $colorkode)

{

$fill_color[] = colorHex($img, $colorkode);

$shadow_color[] = colorHexshadow($img, $colorkode, $shadow_dark);

}

 

$label_place = 5;

 

if (is_array($label))

{

for ($i = 0; $i < count($label); $i++)

{

if ($label_form == 'round' && $show_label)

{

imagefilledellipse($img,$width+11,$label_place+5,10,10,colorHex($img, $colors[$i % count($colors)]));

imageellipse($img,$width+11,$label_place+5,10,10,colorHex($img, $text_color));

}

else if ($label_form == 'square' && $show_label)

{

imagefilledrectangle($img,$width+6,$label_place,$width+16,$label_place+10,colorHex($img, $colors[$i % count($colors)]));

imagerectangle($img,$width+6,$label_place,$width+16,$label_place+10,colorHex($img, $text_color));

}

 

if ($show_percent) $label_output = $number[$i].' ';

if ($show_text) $label_output = $label_output.$label[$i].' ';

if ($show_parts) $label_output = $label_output.$data[$i];

 

imagestring($img,'2',$width+20,$label_place,$label_output,colorHex($img, $text_color));

$label_output = '';

 

$label_place = $label_place + 15;

}

}

$centerX = round($width/2);

$centerY = round($height/2);

$diameterX = $width-4;

$diameterY = $height-4;

 

$data_sum = array_sum($data);

 

$start = 270;

 

for ($i = 0; $i < count($data); $i++)

{

$value += $data[$i];

$end = ceil(($value/$data_sum)*360) + 270;

$slice[] = array($start, $end, $shadow_color[$value_counter % count($shadow_color)], $fill_color[$value_counter % count($fill_color)]);

$start = $end;

$value_counter++;

}

 

for ($i=$centerY+$shadow_height; $i>$centerY; $i--)

{

for ($j = 0; $j < count($slice); $j++)

{

if ($slice[$j][0] != $slice[$j][1]) ImageFilledArc($img, $centerX, $i, $diameterX, $diameterY, $slice[$j][0], $slice[$j][1], $slice[$j][2], IMG_ARC_PIE);

}

}

 

for ($j = 0; $j < count($slice); $j++)

{

if ($slice[$j][0] != $slice[$j][1]) ImageFilledArc($img, $centerX, $centerY, $diameterX, $diameterY, $slice[$j][0], $slice[$j][1], $slice[$j][3], IMG_ARC_PIE);

}

 

OutputImage($img);

ImageDestroy($img);

 

 

function colorHex($img, $HexColorString)

{

$R = hexdec(substr($HexColorString, 0, 2));

$G = hexdec(substr($HexColorString, 2, 2));

$B = hexdec(substr($HexColorString, 4, 2));

return ImageColorAllocate($img, $R, $G, $B);

}

 

function colorHexshadow($img, $HexColorString, $mork)

{

$R = hexdec(substr($HexColorString, 0, 2));

$G = hexdec(substr($HexColorString, 2, 2));

$B = hexdec(substr($HexColorString, 4, 2));

 

if ($mork)

{

($R > 99) ? $R -= 100 : $R = 0;

($G > 99) ? $G -= 100 : $G = 0;

($B > 99) ? $B -= 100 : $B = 0;

}

else

{

($R < 220) ? $R += 35 : $R = 255;

($G < 220) ? $G += 35 : $G = 255;

($B < 220) ? $B += 35 : $B = 255;

}

 

return ImageColorAllocate($img, $R, $G, $B);

}

 

function OutputImage($img)

{

header('Content-type: image/jpg');

ImageJPEG($img,NULL,100);

}

 

?>

Link to comment
Share on other sites

here is the real output from http://69.59.125.225/stripe/new.php

<br />
<b>Notice</b>:  Undefined variable: text_length in <b>/var/www/html/stripe/new.php</b> on line <b>48</b><br />
<br />
<b>Notice</b>:  Undefined variable: xtra_height in <b>/var/www/html/stripe/new.php</b> on line <b>64</b><br />
<br />
<b>Notice</b>:  Undefined variable: value in <b>/var/www/html/stripe/new.php</b> on line <b>112</b><br />
<br />
<b>Notice</b>:  Undefined variable: value_counter in <b>/var/www/html/stripe/new.php</b> on line <b>114</b><br />
<br />
<b>Notice</b>:  Undefined variable: value_counter in <b>/var/www/html/stripe/new.php</b> on line <b>114</b><br />
<br />
<b>Notice</b>:  Undefined variable: value_counter in <b>/var/www/html/stripe/new.php</b> on line <b>116</b><br />

dont know how much of a impact they have on it but i am assuming they are your problem

 

Scott.

 

Link to comment
Share on other sites

here is the real output from http://69.59.125.225/stripe/new.php

<br />
<b>Notice</b>:  Undefined variable: text_length in <b>/var/www/html/stripe/new.php</b> on line <b>48</b><br />
<br />
<b>Notice</b>:  Undefined variable: xtra_height in <b>/var/www/html/stripe/new.php</b> on line <b>64</b><br />
<br />
<b>Notice</b>:  Undefined variable: value in <b>/var/www/html/stripe/new.php</b> on line <b>112</b><br />
<br />
<b>Notice</b>:  Undefined variable: value_counter in <b>/var/www/html/stripe/new.php</b> on line <b>114</b><br />
<br />
<b>Notice</b>:  Undefined variable: value_counter in <b>/var/www/html/stripe/new.php</b> on line <b>114</b><br />
<br />
<b>Notice</b>:  Undefined variable: value_counter in <b>/var/www/html/stripe/new.php</b> on line <b>116</b><br />

dont know how much of a impact they have on it but i am assuming they are your problem

 

Scott.

 

 

Ah, my server has error's reporting but not notices prolly ... I never saw those errors before.

 

Thanks.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.