By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,888 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,888 IT Pros & Developers. It's quick & easy.

including png image with HTML content

P: n/a
Hi! I have nearly cracked this and am stuck on the last bit.

I am asking my visitors to rank 8 different items (a,b,c,d,e,f,g,h) from 1
to 10 and then I want to draw a pie chart of those values. My page
(draw_pie.php) that draws the pie chart works as it should and I link to it
like this ...

<A
HREF="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='. $d.'&e='.$e.'&f='.$f.'&g='
..$g.'&h='.$h.'">Pie Chart</A>

But I want to present the visitor with some explanatory notes and the pie
chart underneath on the same page so I am doing this ...

<IMG
SRC="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='.$ d.'&e='.$e.'&f='.$f.'&g='.
$g.'&h='.$h.'" WIDTH="300" HEIGHT="200">

But all I get is the "missing image" red cross in a 300 x 200 box???

Any ideas?

Help always appreciated.

Paul.
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a


Paul Charlton-Thomson wrote (in part):
<IMG
SRC="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='.$ d.'&e='.$e.'&f='.$f.'&g='.
$g.'&h='.$h.'" WIDTH="300" HEIGHT="200">


Can you post the code from draw_pie.php that sends the image?

Ken

Jul 17 '05 #2

P: n/a
Here's the draw_pie.php code ...

<?php
$segment_size[0] = $_POST['a'];
$segment_size[1] = $_POST['b'];
$segment_size[2] = $_POST['c'];
$segment_size[3] = $_POST['d'];
$segment_size[4] = $_POST['e'];
$segment_size[5] = $_POST['f'];
$segment_size[6] = $_POST['g'];
$segment_size[7] = $_POST['h'];

$width = 300;
$height = 200;

$image = imageCreate($width, $height);
$background = imageColorAllocate($image, 255, 255, 255);

$segment_colour[0] = imageColorAllocate($image, 255, 203, 3);
$segment_colour[1] = imageColorAllocate($image, 220, 101, 29);
$segment_colour[2] = imageColorAllocate($image, 189, 24, 51);
$segment_colour[3] = imageColorAllocate($image, 214, 0, 127);
$segment_colour[4] = imageColorAllocate($image, 98, 1, 96);
$segment_colour[5] = imageColorAllocate($image, 0, 62, 136);
$segment_colour[6] = imageColorAllocate($image, 0, 102, 179);
$segment_colour[7] = imageColorAllocate($image, 0, 145, 195);

$cien[0] = imagecolorallocate($image, 205, 153, 0);
$cien[1] = imagecolorallocate($image, 170, 51, 0);
$cien[2] = imagecolorallocate($image, 139, 0, 1);
$cien[3] = imagecolorallocate($image, 164, 0, 77);
$cien[4] = imagecolorallocate($image, 48, 0, 46);
$cien[5] = imagecolorallocate($image, 0, 12, 86);
$cien[6] = imagecolorallocate($image, 0, 52, 129);
$cien[7] = imagecolorallocate($image, 0, 95, 145);
$cien[8] = imagecolorallocate($image, 0, 65, 56);

$suma = array_sum($segment_size);

$stopnie = 0;
for($i = 0; $i < count($segment_size); $i++){
$start[$i]= $stopnie;
$stop[$i] = $stopnie + round(($segment_size[$i] / $suma) * 360, 0);
$stopnie = $stop[$i];
}

$x = $width / 2;
$size = $width / 7;
$y = $height / 2 - $size / 2 - 1;
for($g = $size; $g > 0; $g--){
for($n = 0; $n < count($segment_size); $n++){
imagefilledarc($image, $x, $y+$g, $width, $height - $size,
$start[$n], $stop[$n], $cien[$n], IMG_ARC_PIE);
}
}

for($i = 0; $i < count($segment_size); $i++){
imagefilledarc($image, $x, $y, $width, $height - $size, $start[$i],
$stop[$i], $segment_colour[$i], IMG_ARC_PIE);

}

header("Content-type: image/png");
imagePNG($image);
imageDestroy($image);
?>
"Ken Robinson" <ke******@rbnsn.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...


Paul Charlton-Thomson wrote (in part):
<IMG
SRC="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='.$ d.'&e='.$e.'&f='.$f.'&g='. $g.'&h='.$h.'" WIDTH="300" HEIGHT="200">


Can you post the code from draw_pie.php that sends the image?

Ken

Jul 17 '05 #3

P: n/a


Paul Charlton-Thomson wrote (in part):
Here's the draw_pie.php code ...

<?php
$segment_size[0] = $_POST['a'];
$segment_size[1] = $_POST['b'];
$segment_size[2] = $_POST['c'];
$segment_size[3] = $_POST['d'];
$segment_size[4] = $_POST['e'];
$segment_size[5] = $_POST['f'];
$segment_size[6] = $_POST['g'];
$segment_size[7] = $_POST['h'];


You're invoking this script with

SRC="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='.$ d.'&e='.$e.'&f='.$f.'&g='.
$g.'&h='.$h.'" WIDTH="300" HEIGHT="200">

Yet you're looking for the parameters in the POST superarray. That will
not work. Use the $_GET superarray (replace $_POST with $_GET) and try
again.

Ken

Jul 17 '05 #4

P: n/a
Ken,

Yes you are right. Sorry ... I have two versions one with $_POST and one
with $_GET commands.

The one I posted was $_POST and should have been $_GET which still does not
work.

All I see is a red cross i.e. image missing.

Paul.

So here's the correct PHP code ...

<?php
$segment_size[0] = $_GET['a'];
$segment_size[1] = $_GET['b'];
$segment_size[2] = $_GET['c'];
$segment_size[3] = $_GET['d'];
$segment_size[4] = $_GET['e'];
$segment_size[5] = $_GET['f'];
$segment_size[6] = $_GET['g'];
$segment_size[7] = $_GET['h'];

$width = 300;
$height = 200;

$image = imageCreate($width, $height);
$background = imageColorAllocate($image, 255, 255, 255);

$segment_colour[0] = imageColorAllocate($image, 255, 203, 3);
$segment_colour[1] = imageColorAllocate($image, 220, 101, 29);
$segment_colour[2] = imageColorAllocate($image, 189, 24, 51);
$segment_colour[3] = imageColorAllocate($image, 214, 0, 127);
$segment_colour[4] = imageColorAllocate($image, 98, 1, 96);
$segment_colour[5] = imageColorAllocate($image, 0, 62, 136);
$segment_colour[6] = imageColorAllocate($image, 0, 102, 179);
$segment_colour[7] = imageColorAllocate($image, 0, 145, 195);

$cien[0] = imagecolorallocate($image, 205, 153, 0);
$cien[1] = imagecolorallocate($image, 170, 51, 0);
$cien[2] = imagecolorallocate($image, 139, 0, 1);
$cien[3] = imagecolorallocate($image, 164, 0, 77);
$cien[4] = imagecolorallocate($image, 48, 0, 46);
$cien[5] = imagecolorallocate($image, 0, 12, 86);
$cien[6] = imagecolorallocate($image, 0, 52, 129);
$cien[7] = imagecolorallocate($image, 0, 95, 145);
$cien[8] = imagecolorallocate($image, 0, 65, 56);

$suma = array_sum($segment_size);

$stopnie = 0;
for($i = 0; $i < count($segment_size); $i++){
$start[$i]= $stopnie;
$stop[$i] = $stopnie + round(($segment_size[$i] / $suma) * 360, 0);
$stopnie = $stop[$i];
}

$x = $width / 2;
$size = $width / 7;
$y = $height / 2 - $size / 2 - 1;
for($g = $size; $g > 0; $g--){
for($n = 0; $n < count($segment_size); $n++){
imagefilledarc($image, $x, $y+$g, $width, $height - $size,
$start[$n], $stop[$n], $cien[$n], IMG_ARC_PIE);
}
}

for($i = 0; $i < count($segment_size); $i++){
imagefilledarc($image, $x, $y, $width, $height - $size, $start[$i],
$stop[$i], $segment_colour[$i], IMG_ARC_PIE);

}

header("Content-type: image/png");
imagePNG($image);
imageDestroy($image);
?>
"Ken Robinson" <ke******@rbnsn.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...


Paul Charlton-Thomson wrote (in part):
Here's the draw_pie.php code ...

<?php
$segment_size[0] = $_POST['a'];
$segment_size[1] = $_POST['b'];
$segment_size[2] = $_POST['c'];
$segment_size[3] = $_POST['d'];
$segment_size[4] = $_POST['e'];
$segment_size[5] = $_POST['f'];
$segment_size[6] = $_POST['g'];
$segment_size[7] = $_POST['h'];
You're invoking this script with

SRC="draw_pie.php?a='.$a.'&b='.$b.'&c='.$c.'&d='.$ d.'&e='.$e.'&f='.$f.'&g='. $g.'&h='.$h.'" WIDTH="300" HEIGHT="200">

Yet you're looking for the parameters in the POST superarray. That will
not work. Use the $_GET superarray (replace $_POST with $_GET) and try
again.

Ken

Jul 17 '05 #5

P: n/a
I have been working on this and I have found a workaround but using IFRAME
which I'm not keen on ... so I can create my image and get it to display
with my HTML using ...

<IFRAME WIDTH="400" HEIGHT="300" SRC="draw_pie.php?a=' . $a. '&b=' . $b.
'&c=' . $c. '&d=' . $d. '&e=' . $e. '&f=' . $f. '&g=' . $g. '&h=' . $h.
'"></IFRAME>';

but I can't get this to work ...

<IMG SRC="draw_pie.php?a=' . $a. '&b=' . $b. '&c=' . $c. '&d=' . $d. '&e=' .
$e. '&f=' . $f. '&g=' . $g. '&h=' . $h. '" WIDTH="300" HEIGHT="200">

Any ideas ???

Thanks,

Paul.
Jul 17 '05 #6

P: n/a
Paul Charlton-Thomson wrote:
I have been working on this and I have found a workaround but using IFRAME
which I'm not keen on ... so I can create my image and get it to display
with my HTML using ...


I wrote a small test script:

<?
$a =5; $b=6;$c=1;$d=10;$e=8;$f=4;$g=10;$h=7;
echo '<IMG SRC="draw_pie.php?a=' . $a . '&amp;b=' . $b . '&amp;c=' . $c
.. '&amp;d=' . $d . '&amp;e=' . $e . '&amp;f=' . $f . '&amp;g=' . $g .
'&amp;h=' . $h . '">';
?>

and used it with the code you posted. I got the graphic with no
problem.

Can you post the code that you are having problems with? Looking at
the code you've posted so far it looks like you're mixing HTML & PHP
without using the <?php & ?> tags correctly.

Ken

Jul 17 '05 #7

P: n/a
Ken,

Problem solved ... doh!

I need to use the $_POST command in the page that presents the HTML and the
<IMG SRC="draw_pie.php?a=1&b=2 ... otherwise I was outputting <IMG
SRC="draw_pie.php?a=&b=&c=&d=

AND

use the $_GET in the draw_pie.php page ...

I was only using the $_GET in draw_pie.php
Thanks for your help - greatly appreciated.

Paul.

"Ken Robinson" <ke******@rbnsn.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Paul Charlton-Thomson wrote:
I have been working on this and I have found a workaround but using IFRAME which I'm not keen on ... so I can create my image and get it to display
with my HTML using ...


I wrote a small test script:

<?
$a =5; $b=6;$c=1;$d=10;$e=8;$f=4;$g=10;$h=7;
echo '<IMG SRC="draw_pie.php?a=' . $a . '&amp;b=' . $b . '&amp;c=' . $c
. '&amp;d=' . $d . '&amp;e=' . $e . '&amp;f=' . $f . '&amp;g=' . $g .
'&amp;h=' . $h . '">';
?>

and used it with the code you posted. I got the graphic with no
problem.

Can you post the code that you are having problems with? Looking at
the code you've posted so far it looks like you're mixing HTML & PHP
without using the <?php & ?> tags correctly.

Ken

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.