www.webdeveloper.com
Results 1 to 13 of 13

Thread: image to string --> string to image

  1. #1
    Join Date
    Nov 2003
    Posts
    287

    image to string --> string to image

    Hi i found two codes one puts converts an image to a string...the other one does it the other way around. Now i have the problem that I can't combine them...don't ask my why but i want a code that first converts an image to a string and afterwards converts the string to an image again...how is this possible??

    Hope someone can help me with this!
    Thanks in advance...i added the script i found.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    What exactly are you trying to do???????

  3. #3
    Join Date
    Nov 2003
    Posts
    287
    Quote Originally Posted by zebdaag
    don't ask me why
    Is what i said in my first post, i just want to know if it's possible and how i can do it!

  4. #4
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Your post doesn't explain anything! Getting an image file into a string is as simple as:
    PHP Code:
    $string file_get_content('image.jpg'); 

  5. #5
    Join Date
    Nov 2003
    Posts
    287
    What i want is a code that puts an image into a string like you said:
    $string = file_get_content('image.jpg');
    and then the code should take the string "$string"
    and make it an image again. With createImageFromString i think...but i don't know how.
    Sorry if it wasn't clear what i wanted, but maybe it sounds so stupid that you can't believe i want this

  6. #6
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    There's an example of that in the manual . Note the the string in the example has previously been base 64 encoded.

  7. #7
    Join Date
    Nov 2003
    Posts
    287
    Quote Originally Posted by bokeh
    There's an example of that in the manual . Note the the string in the example has previously been base 64 encoded.
    Hi Bokeh, I already found that example that's the one attached in my first post. But the thing is i can't get it to work!! I don't know what 64 means so maybe you can help me a bit further with combining the two code i attached in my first post..

    Thanks in advance

  8. #8
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742

  9. #9
    Join Date
    Nov 2003
    Posts
    287
    okay well now i know what base64 is but it doesn't help me any further...
    cause the image the source i get from php when i do file_get_contents is not base64....

    when you see this code:
    PHP Code:
    <?php
    $loadFile 
    "test.jpg";
    $im imagecreatefromstring(file_get_contents($loadFile));
    imagejpeg($im);
    ?>
    it looks simpel as **** but why don't i see an image???
    why is the only thing i see the source of the image??
    can someone help me??

  10. #10
    Join Date
    Apr 2006
    Posts
    93
    you have to set the content type to image/jpeg or something.

    EDIT: try this:
    PHP Code:
    <?php
    $im 
    = @imagecreatefromstring(file_get_contents('image.jpg'));
    imagejpeg($im);
    header ("Content-type: image/jpg");
    ?>
    Last edited by Little Goat; 05-25-2006 at 02:24 PM.

  11. #11
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by Little Goat
    PHP Code:
    <?php
    $im 
    = @imagecreatefromstring(file_get_contents('image.jpg'));
    imagejpeg($im);
    header ("Content-type: image/jpg");
    ?>
    You have the order a bit wrong; the header needs to be sent before the image:
    PHP Code:
    <?php
    header 
    ('Content-Type: image/jpg');
    imagejpeg(imagecreatefromstring(file_get_contents('image.jpg')), null,100);
    ?>
    But all this is pretty pointless apart from being a learning exercise because nothing is actually being done with the image itself.
    Last edited by bokeh; 05-25-2006 at 03:04 PM.

  12. #12
    Join Date
    Apr 2006
    Posts
    93
    well, it worked for me.
    LG

  13. #13
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by Little Goat
    well, it worked for me.
    LG
    It would work on servers with output buffering turned on by default. This is probably about 5% of servers. My recommendation is to write code that will work in 100% of cases.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles