473,217 Members | 2,136 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,217 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 1692


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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.