开发者

Can you save an image that you used imagecopyresized() on to MySQL?

I've been trying multiple ways to try to make thumbnails for my photo gallery, but since I couldn't find a way to resize a picture while it was a BLOB, I decided to try to save it to MySQL as a BLOB of its own. However it won't let me save it and gives me nothing when I echo it. Any ideas how I could save it to MySQL?

$tmp_img = imagecreatetruecolor($tw,$th);
imagecopyresized($tmp_img, $im, 0, 0, 0, 0, $tw, $th, $size[0],$size[1]);
ob_start();
imagejpeg($tmp_img);
$i=ob_get_clean();
$fp=fopen($nar,'w');
fwrite($fp,$i);
fclose($fp);
$filename_thumb=addslashes(file_get_contents($_开发者_开发技巧FILES['nar']));
mysql_query("INSERT INTO photos (filename,caption,album,thumbl) 
VALUES ('" . $filename . "','" . $caps . "','" . $_POST['albums'] . "','" .  
$filename_thumb . "')") or die(mysql_error());


$tmp_img isn't a filename, it's an GD image resource. You have to write an image from it by using one of imagejpeg(), imagepng() or imagegif().

You can use a temporary file or the output buffer to store the image data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜