reading a dynamic image to a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • herc777@hotmail.com

    #1

    reading a dynamic image to a string

    This is how I put a jpg into a string.

    ---------------------------------
    $File1 = "pic1.jpg";

    // open for read/binary-safe
    $objFH = fopen( $File1, "rb" );
    $strBuffer1 = fread( $objFH, filesize( $File1 ) );
    fclose( $objFH );
    ----------------------------------

    Which is fine when pic1.jpg exists, but pic1.jpg is created live by
    calling pic1.php which outputs a jpg, pic1.jpg.

    If I try fopen( "pic1.php", "rb" ) it will give me the php file, I want
    it to open the image file, preferably without writing it to disk.

    Herc

  • Peter van Schie

    #2
    Re: reading a dynamic image to a string

    I'm not sure if this is what you mean, but if you want to prevent the
    fopen call when pic1.jpg doesn't exist, just use file_exists():

    $File1 = "pic1.jpg";

    // open for read/binary-safe
    if (file_exists($F ile1))
    {
    $objFH = fopen( $File1, "rb" );
    $strBuffer1 = fread( $objFH, filesize( $File1 ) );
    fclose( $objFH );
    }

    --


    Comment

    • herc777@hotmail.com

      #3
      Re: reading a dynamic image to a string

      thanks but that's not what I was after, there's no pic1.jpg on the
      disk, its the output from pic1.php.

      like this
      <img src="button.php ?text=home">

      will put an image on your page, a button graphic with the word 'home',
      but there's no button.jpg anywhere on the server.

      Is is possible to read the file button.jpg without writing it to disk
      1st, you have to invoke PHP to parse button.php?

      Herc

      Comment

      • Peter van Schie

        #4
        Re: reading a dynamic image to a string

        Okay, I get what you mean now.
        Isn't it an option to write the imagedata to a session-var and then
        read that sessionvar from the script including the button-creation
        script?
        That way you don't have to worry about the imagefile being overwritten
        each time a user opens the page, since each user has his own session.

        Peter.

        --


        Comment

        • Chung Leong

          #5
          Re: reading a dynamic image to a string

          Do $data = @file_get_conte nts("http://<server>/button.php?text =home").

          Naturally, you'd need to resolve the relative URL first.

          Comment

          • herc777@hotmail.com

            #6
            Re: reading a dynamic image to a string

            thanks that works!

            Herc

            Comment

            • herc777@hotmail.com

              #7
              Re: reading a dynamic image to a string

              button.php uses this

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

              and returns as a binary file instead of html. so button.jpg can't be
              overwritten its just like fetching HTML but you fetch a graphic
              instead. it will run the same routine again and again for the same
              graphic though.

              Herc

              Comment

              Working...