SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP GD Thumbnail Generation

    I'm trying to generate thumbnails from larger images at upload time & strore the base64 encoded binary data in a db but the
    PHP Code:
    imagejpeg 
    method can only either output the generated date straight to the browser or to a file which doesn't help me capture that output to feed it into the db.

    Storing the original uploaded images in the db is fine but trying to generate the thumbs only fly from that data in the db is also seemingly impossible since the
    PHP Code:
    createimagefromjpeg 
    method takes a file as input & not a string of binary data...catch 22.

    I don't want to have to interact with the filesystem (i.e. write/read files) as this can be a problem with varying hosts, permissions, etc.

    Any suggestions?

  2. #2
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    ob_start(); // Start buffing output
    imagejpeg$newimage''90 );
    $ImageData ob_get_contents();
    $ImageDataLength ob_get_length();
    ob_end_clean(); // Empty the output buffer and stop buffering. 
    If the filename portion is empty, imagejpeg simply streams out the data. So you use output buffering to capture it.

    afterwards use $ImageData and $ImageDataLength as necessary.

  3. #3
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!!! Will give it a bash.

  4. #4
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works perfectly! Also found a way to maintain the aspect ratio when resizing.


Bookmarks

Posting Permissions

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