Image basics

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • swisscheese

    Image basics

    After reading 5 tutorials, I must be missing something basic.[color=blue]
    >From a .php web page how can I output an image?[/color]
    I created and drew the image and did:

    header("Content-type: image/png");
    imagepng($image ,"image.png" );
    ?>
    ....
    <BODY
    <img src="./image.png" height="400" width="400"></img>

    But I get the broken image icon.
    Also I don't really want to create the file - just output the image
    directly.

  • swisscheese

    #2
    Re: Image basics

    .... BTW - I don't want to create a separate file for the image code as
    the code calls functions in the rest of the php code.

    Comment

    • Iván Sánchez Ortega

      #3
      Re: Image basics

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      swisscheese wrote:
      [color=blue]
      > imagepng($image ,"image.png" );[/color]
      [color=blue]
      > Also I don't really want to create the file - just output the image
      > directly.[/color]

      <?php
      imagepng($image );
      ?>

      - --
      - ----------------------------------
      Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

      http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
      MSN:i_eat_s_p_a _m_for_breakfas t@hotmail.com
      Jabber:ivansanc hez@jabber.org ; ivansanchez@kde talk.net
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.2 (GNU/Linux)

      iD8DBQFDpduv3jc Q2mg3Pc8RAm9yAJ 0RYC8WQ6loIrniN wuZhKeyt93P8wCe IUgs
      vsjHWEQ1pn4KGPE KsMnyE+I=
      =JZku
      -----END PGP SIGNATURE-----

      Comment

      • swisscheese

        #4
        Re: Image basics

        Thanks but tried that also.
        And what goes in place of:
        <img src="./image.png" ...

        Comment

        • NC

          #5
          Re: Image basics

          swisscheese wrote:[color=blue]
          >
          > After reading 5 tutorials, I must be missing something basic.[/color]

          The key is to realize that you are going to need TWO scripts:

          1. The script (or even a static HTML file) containing the image
          tag. Example: <IMG SRC="image.php" >

          2. The PHP script posing as image. Be sure that there are no
          symbols in the script file before the first "<?" or "<?php".

          This will ensure that the browser will render the output of
          the script as an image.
          [color=blue]
          > Also I don't really want to create the file - just output the image
          > directly.[/color]

          You don't have to if you don't want to... In the first script (or an
          HTML file) you write:

          <IMG SRC="image.php" >

          In the image.php, you write:

          header("Content-type: image/png");
          // Here's where you actually draw the image...
          imagepng($im);
          imagedestroy($i m);

          Cheers,
          NC

          Comment

          • Iván Sánchez Ortega

            #6
            Re: Image basics

            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA1

            swisscheese wrote:
            [color=blue]
            > Thanks but tried that also.
            > And what goes in place of:
            > <img src="./image.png" ...[/color]

            <img src='image.php? parameters'/>

            Where image.php is something like:

            <?php
            // init and draw $image
            imagepng($image );
            ?>

            - --
            - ----------------------------------
            Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

            Los experimentos deben ser análogos, todos deben fallar de la misma
            manera.
            -- Cuarta Regla de Finagle.

            -----BEGIN PGP SIGNATURE-----
            Version: GnuPG v1.4.2 (GNU/Linux)

            iD8DBQFDpnBN3jc Q2mg3Pc8RAs79AJ wOYs6rxXiId/pzvzZJ3GD5tmA/7wCeNCvK
            ryPNILcIVK3fCBJ jcp+JaEw=
            =Injx
            -----END PGP SIGNATURE-----

            Comment

            • jimlewis@emachineshop.com

              #7
              Re: Image basics

              I was afraid of that but thanks for confirming it. But the image needs
              several functions and a lot of data from the other module. Is there a
              way to call functions across modules?

              Comment

              • Oli Filth

                #8
                Re: Image basics

                Note: please don't snip what you're replying to...

                jimlewis@emachi neshop.com wrote:[color=blue]
                > I was afraid of that but thanks for confirming it. But the image needs
                > several functions and a lot of data from the other module. Is there a
                > way to call functions across modules?[/color]

                Either sessions or GET variables.

                e.g. for GET variables, in your main script if you create your HTML as
                such:

                <IMG src="image.php? var1=blah">

                Then in image.php you should have $_GET["var1"] available.

                --
                Oli

                Comment

                • jimlewis@emachineshop.com

                  #9
                  Re: Image basics

                  Thanks.

                  Comment

                  Working...