Image in a Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • infoseekar
    New Member
    • Mar 2008
    • 34

    Image in a Table

    CAn someone help me to put an image inside a <table> in php. i have used echo '<table>' function but i did not work form me. it out put some hex codes.

    [code=php]

    <?php
    echo '<table>';
    <tr>
    <td>
    $file='cow.jpg' ;
    $src_img = imagecreatefrom jpeg($file);
    $srcsize = getimagesize($f ile);

    $dest_x = 250;
    $dest_y = (250 / $srcsize[0]) * $srcsize[1];
    $dst_img = imagecreatetrue color($dest_x, $dest_y);

    imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0,
    $dest_x, $dest_y, $srcsize[0], $srcsize[1]);

    header("content-type: image/jpeg");

    imagejpeg($dst_ img);
    </td>
    </tr>
    echo '</table>';
    ?>
    [/code]

    thanks
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    At the beginning, you have echo '<table>'; but then you have <tr>??? All you code is in php, so you need to echo any html like so:
    [code=php]
    <?php
    echo '<table><tr><td >';
    $file='cow.jpg' ;
    $src_img = imagecreatefrom jpeg($file);
    $srcsize = getimagesize($f ile);

    $dest_x = 250;
    $dest_y = (250 / $srcsize[0]) * $srcsize[1];
    $dst_img = imagecreatetrue color($dest_x, $dest_y);

    imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);

    header("content-type: image/jpeg");

    imagejpeg($dst_ img);

    echo '</td></tr></table>';
    ?>
    [/code]

    I am not familiar with the imaging function you have used, so I will leave that for someone else to comment on, however I am pretty sure your header line will not work as this needs to be done at the top of the page. I could be wrong, but I always have trouble with that. Fix up your php echo-ing and then also post what the output is so maybe we can have a better idea.

    Comment

    • infoseekar
      New Member
      • Mar 2008
      • 34

      #3
      Originally posted by TheServant
      At the beginning, you have echo '<table>'; but then you have <tr>??? All you code is in php, so you need to echo any html like so:
      [code=php]
      <?php
      echo '<table><tr><td >';
      $file='cow.jpg' ;
      $src_img = imagecreatefrom jpeg($file);
      $srcsize = getimagesize($f ile);

      $dest_x = 250;
      $dest_y = (250 / $srcsize[0]) * $srcsize[1];
      $dst_img = imagecreatetrue color($dest_x, $dest_y);

      imagecopyresamp led($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);

      header("content-type: image/jpeg");

      imagejpeg($dst_ img);

      echo '</td></tr></table>';
      ?>
      [/code]

      I am not familiar with the imaging function you have used, so I will leave that for someone else to comment on, however I am pretty sure your header line will not work as this needs to be done at the top of the page. I could be wrong, but I always have trouble with that. Fix up your php echo-ing and then also post what the output is so maybe we can have a better idea.
      Thanks TheServant . Its working not but instead of the picture some hex codes are displaying inside the table.

      thanks

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        I'm presuming you mean "it's working now"? Anyway, please post what is appearing in the table... I have an inkling about what it is, but I need to see the output first.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          The problem here is that you are printing the image data as HTML.
          As a result, the image is being displayed as if it were a string of letters.

          What you need to do is use the <img> tag and link to the image you want displayed.

          If you are trying to modify an existing image using PHP code, and you want that image in your table, you will simply have to put that code into a separate PHP file and link to that in your <img> tag.

          Comment

          • infoseekar
            New Member
            • Mar 2008
            • 34

            #6
            Originally posted by Atli
            Hi.

            The problem here is that you are printing the image data as HTML.
            As a result, the image is being displayed as if it were a string of letters.

            What you need to do is use the <img> tag and link to the image you want displayed.

            If you are trying to modify an existing image using PHP code, and you want that image in your table, you will simply have to put that code into a separate PHP file and link to that in your <img> tag.
            Thanks for your help.

            I have a php code to get an image then size the the image and display it. what i want to do is to display that image inside a table.

            I will try what u recommended..

            Comment

            • infoseekar
              New Member
              • Mar 2008
              • 34

              #7
              Originally posted by TheServant
              I'm presuming you mean "it's working now"? Anyway, please post what is appearing in the table... I have an inkling about what it is, but I need to see the output first.

              The output was some hex codes inside the table.

              thanks

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                Originally posted by infoseekar
                The output was some hex codes inside the table.

                thanks
                Never mind, Alti suggested basically what I was going to suggest. Tell us how that goes.

                Comment

                Working...