473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

including png image with HTML content

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
7 1698


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
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


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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kenny | last post by:
I have been trying to write a script that will increase the size of and image when you mouse over it, and decrease it to original size, when you mouse out. After a couple of attempts, this is what...
0
by: gerard.buskermolen | last post by:
Hello world, I have an ASP.NET application that returns HTML to the browser that should be read by MS Word. To do this I set Response.ContentType = ContentType.Word...
8
by: Leszek | last post by:
Hi. Could you help solve the problem: i have a file that has two includes: //my script <?php include(.'/prog1.php'); include(.'/prog2.php'); ?>
3
by: premier | last post by:
I have a web page that's taking in data from text boxes, drawing a chart to represent the data, and then outputting the chart in PNG format. What I cant figure out how to do, is to output the...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
24
by: Manuel | last post by:
Is it possible to embed an image, like a company logo in a CDOSYS generated message? If yes, I´ll apreciate some code sample. I´ve been able to format messages in html the way I like, but I...
6
by: Rob | last post by:
Hello, I'm sure this has come up before. I have need for a collection of all elements/objects in an HTML document that have any kind of an attribute (HTML or CSS) that is making use of a URL to...
11
by: Chris Beall | last post by:
See http://pages.prodigy.net/chris_beall/Demo/photo%20block%20experiments.html I've ended up with what seems like a rather complex structure for what I thought would be a somewhat simple...
2
by: thephatp | last post by:
I'm having a problem with IE rendering correctly. I'm experimenting with using all div's in my pages now, and I'm not very familiar with the quirks of IE. I have created a sample page, and I'm...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.