【发布时间】:2012-01-16 12:01:12
【问题描述】:
我使用以下字段将原始图像保存在我的数据库中:
file_name VARCHAR(255)
mime_type VARCHAR(255)
file_size INT
file_data LONGBLOB
我保存的 PHP 代码是:
$image = $_FILES['image'];
$info = getImageSize($image['tmp_name']);
$query = "CALL saveImageInDataBase('" .
mysql_real_escape_string(file_get_contents($image['tmp_name'])) . "', '" .
mysql_real_escape_string($image['name']) . "', '" .
mysql_real_escape_string($info['mime']) . "', " . $image['size'] . ")";
$result = mysql_query($query);
我想从服务器中的上述数据中创建原始图像的缩略图(我正在使用 PHP),以便在网站上显示(显示图像链接列表)。
谁能告诉我最简单的方法?
【问题讨论】:
-
为什么不直接将图像文件保存在服务器的本地目录中?这会更容易一些,另一方面,这种技术的缺点(将图像文件保存在数据库中)是您的站点加载速度将比您预期的要慢,因为数据仍需要由服务器解析,这在处理时间
-
@juand 是的,我尝试使用 GD 库
$save = 'myfile.jpg'; $file = 'orphinal.jpg'; $size = 0.45; header('Content-type: image/jpeg') ; list($width, $height) = getimagesize($file) ; $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ;创建和保存保存在服务器本地目录中的图像缩略图,但我想为保存在 blob 上的图像使用它 -
@colighto 我已经完成了我的网站将图像保存在 blob 上。这将是一个包含大量图像的网站
-
@shehan:如果提供的解决方案有效,请接受。
标签: php mysql gd blob thumbnails