您可以将使用 imagecopyresized() 的图像保存到 MySQL 吗?
我一直在尝试多种方法来尝试为我的照片库制作缩略图,但由于我找不到调整图片大小的方法,当它是 BLOB 时,我决定尝试将其作为其 BLOB 保存到 MySQL自己的。然而,它不会让我保存它,并且当我回显它时,它不会给我任何东西。有什么想法可以将它保存到 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());
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());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$tmp_img
不是文件名,它是 GD 图像资源。您必须使用imagejpeg()
之一编写图像href="http://php.net/imagepng" rel="noreferrer">imagepng()
或imagegif()
。您可以使用临时文件或输出缓冲区来存储图像数据。
$tmp_img
isn't a filename, it's an GD image resource. You have to write an image from it by using one ofimagejpeg()
,imagepng()
orimagegif()
.You can use a temporary file or the output buffer to store the image data.