Hi,
I would like to store an image created with the GD library in a session variable. To do this I would need to convert the image to a string, then store it. I would also be able to read it back out as a valid image (just use echo?)

How can I accomplish this.

Thankyou. 🙂

    You might try [man]convert_uuencode/man/[man]convert_uudecode/man or [man]base64_encode/man/[man]base64_decode/man, doing a little testing to see which is more efficient and if either creates a smaller string. If the image is large, either mode may become memory intensive. It might be better in that case to save it in a BLOB field in a database, or just save it as an image file in a temp dir or such.

      thankyou for the quick reply I will look into them and see how it goes!

        How large would the image have to be for it to become too memory intensive (just a rough estimate would do). At the moment I am limiting images to 1mb.

          Okay, I'm not sure that I am going about this the right way, however I tried both methods described and they both failed.

          Basically what I am doing is passing the image reference (the image I created using GD, i.e. $new_image = imagecreatetruecolor($new_width, $new_height)😉 to the methods described above as such:

          base64_encode($new_image);
          

          I'm receiving this warning:

          Warning: base64_encode() expects parameter 1 to be string, resource given in C:\xampplite\htdocs\generate_picture.php on line 55

          I expect this to be because I am passing the file reference (or pointer? dunno 🙂 ) to the function as opposed to the actual image data in memory. I am unable to retrieve this image data from the memory (I don't know how.)

          Help?

            Dont worry - as opposed to all these sessions and stuff, I am just going to store a temporary file. Thanks anyway!

              JamesBrauman;10885560 wrote:

              Dont worry - as opposed to all these sessions and stuff, I am just going to store a temporary file. Thanks anyway!

              My guess is that you will find that a more manageable option, anyway.

              Just FYI, for the other stuff you would have had to actually generate the image itself and save it in the session data (e.g. via imagepng() or such), rather than just the image resource, as once the script terminates or an imagedestroy() is executed on it, that resource will be useless. This is why I thought it could become a system resource drain, since you would be saving the entire image plus whatever overhead is required to do so.

                Write a Reply...