I have managed to save the bindata from a jpeg file into a blob in mysql, however saving the bindata from an imagecreate() call into a blob has totally stumped me!

I've tried this:

ob_start();
imagejpeg($image_thumb);
$image_thumb_string = ob_get_contents();
ob_end_flush();

but when I retreive the picture from the blob is just outputs weird characters.

I know I have the content-type header right and pulling out a blob created from an actual file works fine.

All I need is to know how to get the bindata from a resource indetifer that is returned from imagecreate() and I'll be set!

Thanks

    Hey there,

    I've found a semi-acceptable solution that uses temporary files, here's a snipet:

    // Save the thumbnail to a temporary file
    $tmp_filename = "/some/tmp/dir/tmp.jpg";
    imagejpeg($image_thumb,$tmp_filename);

    // Try to open the file
    $fp = @fopen($tmp_filename, "r");
    if (!$fp) {
    unlink($tmp_filename);
    return FALSE;
    }

    // Extract the picture data
    $bin_data = addslashes(fread($fp, filesize($tmp_filename)));

    I would still like to do the job without using tmporary files, but this will do for now.

      Write a Reply...