Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    34
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Php GD save in database help..

    Hi, i know that you can save a image create by the GD library to the filesystem by:

    imagejpeg($image_resource, $newName");

    but how do i save it to the database?
    and how do i get the filesize of the generated image?


    thank you.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Capture its output using an output buffer:
    PHP Code:
    ob_start();
    imagejpeg($imJPGHandlenull100);
    $obImageData ob_get_contents();
    ob_end_flush(); // use ob_end_clean if you don't want to display the image 
    Alternatively, you could write to a file, read it, copy it, and unlink it. Seems like too much work for my liking :P

    To get the size, $obImageData (in my example) should be a binary string. I believe you can simply use strlen on it. If it doesn't work, I'll figure out a solution for you (can't test where I am).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    uncleroxk (12-15-2008)

  • #3
    Regular Coder kokjj87's Avatar
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    279
    Thanks
    1
    Thanked 55 Times in 54 Posts
    To add on to fou-lu.... =)

    PHP Code:
    ob_start();
    imagejpeg($imJPGHandlenull100);
    $obImageData ob_get_contents();
    $obImageSize ob_get_length();   //get the file size in byte
    ob_end_flush(); // use ob_end_clean if you don't want to display the image 

  • Users who have thanked kokjj87 for this post:

    uncleroxk (12-15-2008)


  •  

    Posting Permissions

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