Can GD load an image from another php script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Darkbyte [Work]

    Can GD load an image from another php script?

    Hi everybody!!!
    I have a script (foo.php) which uses GD to create an image and sends it
    to the browser:

    <?php
    $img = imagecreatefrom png("mypng.png" );

    /* other stuff */

    header("Content-type: image/png");
    imagepng($img);

    imagedestroy($i mg);
    ?>

    I also have another php script: goofy.php.
    How can I use imagecreatefrom png to load the result of foo.php (without
    saving it on the hard disk first)?

    I tried with: imagecreatefrom png("foo.php") but doesn't work...
    Can anyone help me, please?

    I'm sorry for my bad english...

    --
    Quando noi ignoranti eravamo di più, tutto era più bello...
    (A. Celentano)

    Per rispondermi in privato:
    s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t
  • Oli Filth

    #2
    Re: Can GD load an image from another php script?

    Darkbyte [Work] said the following on 03/01/2006 19:57:[color=blue]
    > Hi everybody!!!
    > I have a script (foo.php) which uses GD to create an image and sends it
    > to the browser:
    >
    > <?php
    > $img = imagecreatefrom png("mypng.png" );
    >
    > /* other stuff */
    >
    > header("Content-type: image/png");
    > imagepng($img);
    >
    > imagedestroy($i mg);
    > ?>
    >
    > I also have another php script: goofy.php.
    > How can I use imagecreatefrom png to load the result of foo.php (without
    > saving it on the hard disk first)?
    >
    > I tried with: imagecreatefrom png("foo.php") but doesn't work...
    > Can anyone help me, please?[/color]

    Well, you could do it with the absolute HTTP URL, i.e.:

    imagcreatefromp ng("http://example.com/blah/foo.php");

    (assuming allow_url_fopen is enabled).

    However, doing a complete HTTP transaction just to get an image from
    yourself is overkill.

    A more sensible, programmatic way of doing this is to put the
    image-creation stuff from foo.php into a function in an include() file,
    and then call it from foo.php and goofy.php.

    --
    Oli

    Comment

    • Lüpher Cypher

      #3
      Re: Can GD load an image from another php script?

      Darkbyte [Work] wrote:[color=blue]
      > Hi everybody!!!
      > I have a script (foo.php) which uses GD to create an image and sends it
      > to the browser:
      >
      > <?php
      > $img = imagecreatefrom png("mypng.png" );
      >
      > /* other stuff */
      >
      > header("Content-type: image/png");
      > imagepng($img);
      >
      > imagedestroy($i mg);
      > ?>
      >
      > I also have another php script: goofy.php.
      > How can I use imagecreatefrom png to load the result of foo.php (without
      > saving it on the hard disk first)?
      >
      > I tried with: imagecreatefrom png("foo.php") but doesn't work...
      > Can anyone help me, please?
      >[/color]


      Try this:

      $img = imagecreatefrom string(file_get _contents("http ://.../foo.php"));

      However, *do* use http:// in the name so that the function loads the
      page and not the text file.


      --

      - lüpher
      ---------------------------------------------
      "Man sieht nur das, was man weiß" (Goethe)

      Comment

      • Darkbyte [Work]

        #4
        Re: Can GD load an image from another php script?

        > Well, you could do it with the absolute HTTP URL, i.e.:[color=blue]
        >
        > imagcreatefromp ng("http://example.com/blah/foo.php");[/color]

        Oh yes, I already was doing it... I just was looking for another way to
        force imagecreatefrom png() to "execute" my script rather then read it...

        [cut]
        [color=blue]
        > A more sensible, programmatic way of doing this is to put the
        > image-creation stuff from foo.php into a function in an include() file,
        > and then call it from foo.php and goofy.php.[/color]

        Aehm... I'm using my foo.php script in the html code:

        <img src="/blah/foo.php?width=3 20&height=100" border="0" />

        Assuming I'm going to put the stuff into a function, and assuming I'm
        going to create a php script that just calls that function so I can load
        the image directly from html code, how can it help me with
        imagecreatefrom png()?
        How could I use the function with imagecreatefrom png()?

        --
        Quando noi ignoranti eravamo di più, tutto era più bello...
        (A. Celentano)

        Per rispondermi in privato:
        s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t

        Comment

        • Darkbyte [Work]

          #5
          Re: Can GD load an image from another php script?

          > Assuming I'm going to put the stuff into a function, and assuming I'm[color=blue]
          > going to create a php script that just calls that function so I can load
          > the image directly from html code, how can it help me with
          > imagecreatefrom png()?
          > How could I use the function with imagecreatefrom png()?[/color]


          DONE!!! DONE!!! AUHAUHAUHAUHAUH AUHA LOOOOOOLLLLL :)

          function mystuff($width= 1, $height=1)
          {
          $img = imagecreatetrue color($width, $height);
          /* stuff here */
          imagepng($img);
          }

          $img = imagecreatefrom string(mystuff( 320, 200));
          header("Content-type: image/png");
          imagepng($img);
          imagedestroy($i mg);

          That's cool!!! :)

          Thanks everybodyyyyyyy y!!!
          :) :) :) :)

          --
          Quando noi ignoranti eravamo di più, tutto era più bello...
          (A. Celentano)

          Per rispondermi in privato:
          s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t

          Comment

          • Oli Filth

            #6
            Re: Can GD load an image from another php script?

            Darkbyte [Work] said the following on 04/01/2006 09:20:[color=blue][color=green]
            >> Assuming I'm going to put the stuff into a function, and assuming I'm
            >> going to create a php script that just calls that function so I can
            >> load the image directly from html code, how can it help me with
            >> imagecreatefrom png()?
            >> How could I use the function with imagecreatefrom png()?[/color]
            >
            >
            >
            > DONE!!! DONE!!! AUHAUHAUHAUHAUH AUHA LOOOOOOLLLLL :)
            >
            > function mystuff($width= 1, $height=1)
            > {
            > $img = imagecreatetrue color($width, $height);
            > /* stuff here */
            > imagepng($img);
            > }
            >
            > $img = imagecreatefrom string(mystuff( 320, 200));
            > header("Content-type: image/png");
            > imagepng($img);
            > imagedestroy($i mg);
            >[/color]

            What??? This code is nonsensical!

            mystuff() uses imagepng() to output an image to the browser, and has no
            return value. Therefore you're effectively calling
            imagecreatefrom string(NULL), which just throws warnings. This means that
            $img == FALSE, so imagepng() and imagedestroy() fail and throw warnings
            as well. Comment out the header() line and you'll see what I mean.

            The only reason this appears to work is the combination of mystuff()
            outputting (*not* returning) PNG data, coupled with the Content-Type header.


            --
            Oli

            Comment

            • Darkbyte [Work]

              #7
              Re: Can GD load an image from another php script?

              > What??? This code is nonsensical!

              Ja!!! It's true, but I changed the code to some other:

              function create_my_image ($w=1, $h=1)
              {
              $img = @imagecreatetru ecolor($w, $h);
              if ($img)
              {
              /* Other stuff here */
              }
              return $img;
              }

              and I use it as:

              <?php
              include("inc/mod_image.php") ;

              if ($my_img = create_my_image (320, 200))
              {
              /* Other stuff to the image */

              header("Content-type: image/png");
              imagepng($my_im g);

              imagedestroy($m y_img);
              }
              ?>

              This should work better... or shouldn't?

              --
              When ignorants were more, everything was better...
              (A. Celentano)

              Per rispondermi in privato:
              s e p r a n o(punto)a n t o n i o(chiocciola)l i b e r o(punto)i t

              Comment

              Working...