including png image with HTML content

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Charlton-Thomson

    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.p hp?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.


  • Ken Robinson

    #2
    Re: including png image with HTML content



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

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

    Ken

    Comment

    • Paul Charlton-Thomson

      #3
      Re: including png image with HTML content

      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($wi dth, $height);
      $background = imageColorAlloc ate($image, 255, 255, 255);

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

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

      $suma = array_sum($segm ent_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($i mage);
      ?>


      "Ken Robinson" <kenrbnsn@rbnsn .com> wrote in message
      news:1119956042 .173572.168750@ g47g2000cwa.goo glegroups.com.. .[color=blue]
      >
      >
      > Paul Charlton-Thomson wrote (in part):[color=green]
      > > <IMG
      > >[/color][/color]
      SRC="draw_pie.p hp?a='.$a.'&b=' .$b.'&c='.$c.'& d='.$d.'&e='.$e .'&f='.$f.'&g=' .[color=blue][color=green]
      > > $g.'&h='.$h.'" WIDTH="300" HEIGHT="200">[/color]
      >
      > Can you post the code from draw_pie.php that sends the image?
      >
      > Ken
      >[/color]


      Comment

      • Ken Robinson

        #4
        Re: including png image with HTML content



        Paul Charlton-Thomson wrote (in part):[color=blue]
        > 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'];[/color]

        You're invoking this script with

        SRC="draw_pie.p hp?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

        Comment

        • Paul Charlton-Thomson

          #5
          Re: including png image with HTML content

          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($wi dth, $height);
          $background = imageColorAlloc ate($image, 255, 255, 255);

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

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

          $suma = array_sum($segm ent_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($i mage);
          ?>


          "Ken Robinson" <kenrbnsn@rbnsn .com> wrote in message
          news:1119981346 .078370.94460@g 47g2000cwa.goog legroups.com...[color=blue]
          >
          >
          > Paul Charlton-Thomson wrote (in part):[color=green]
          > > 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'];[/color]
          >
          > You're invoking this script with
          >
          >[/color]
          SRC="draw_pie.p hp?a='.$a.'&b=' .$b.'&c='.$c.'& d='.$d.'&e='.$e .'&f='.$f.'&g=' .[color=blue]
          > $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
          >[/color]


          Comment

          • Paul Charlton-Thomson

            #6
            Re: including png image with HTML content

            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.p hp?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.p hp?a=' . $a. '&b=' . $b. '&c=' . $c. '&d=' . $d. '&e=' .
            $e. '&f=' . $f. '&g=' . $g. '&h=' . $h. '" WIDTH="300" HEIGHT="200">

            Any ideas ???

            Thanks,

            Paul.


            Comment

            • Ken Robinson

              #7
              Re: including png image with HTML content

              Paul Charlton-Thomson wrote:[color=blue]
              > 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 ...
              >[/color]

              I wrote a small test script:

              <?
              $a =5; $b=6;$c=1;$d=10 ;$e=8;$f=4;$g=1 0;$h=7;
              echo '<IMG SRC="draw_pie.p hp?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

              Comment

              • Paul Charlton-Thomson

                #8
                Re: including png image with HTML content

                Ken,

                Problem solved ... doh!

                I need to use the $_POST command in the page that presents the HTML and the
                <IMG SRC="draw_pie.p hp?a=1&b=2 ... otherwise I was outputting <IMG
                SRC="draw_pie.p hp?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" <kenrbnsn@rbnsn .com> wrote in message
                news:1120001920 .659251.255680@ g44g2000cwa.goo glegroups.com.. .[color=blue]
                > Paul Charlton-Thomson wrote:[color=green]
                > > I have been working on this and I have found a workaround but using[/color][/color]
                IFRAME[color=blue][color=green]
                > > which I'm not keen on ... so I can create my image and get it to display
                > > with my HTML using ...
                > >[/color]
                >
                > I wrote a small test script:
                >
                > <?
                > $a =5; $b=6;$c=1;$d=10 ;$e=8;$f=4;$g=1 0;$h=7;
                > echo '<IMG SRC="draw_pie.p hp?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
                >[/color]


                Comment

                Working...