【发布时间】:2014-05-22 15:00:22
【问题描述】:
我是 php 新手,我正在尝试建立一个照片网站。我已经设法让上传功能正常工作(作为 blob 发送到数据库并使用自定义 url 显示它)。现在,我想检索这个 blob 数据并自动为其制作缩略图。不幸的是,我只看到带有我指定宽度和高度的黑色背景的画布格式。有人能指出我正确的方向吗?
get_thumb_function.php:
// db_connect
include 'databaseconnection.php';
// get id
$id = $_GET['id'];
// select image from id
$query = mysqli_query($db,"SELECT * FROM images WHERE id='$id'");
$rij = mysqli_fetch_array($query);
// content image
$content = $rij['image'];
// get content type
header('Content-type: image/jpg');
$filename = $content;
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = 100;
$new_height = 100;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
$thumb = imagejpeg($image_p, null, 100);
echo $thumb;
这是我尝试检索缩略图图像的脚本。 index.php
// Alle images uit de database
$query = mysqli_query($db, "SELECT * FROM images LIMIT 0, 9"); // Maximaal 9 foto's
//$id = $row['id'];
while ($row = mysqli_fetch_assoc($query)) {?>
<a href="image.php?id=<?php echo $row['id']; ?>"><img src="get_thumb_function.php?id=<?php echo $row['id']; ?>"></a>
<?php
}//endwhile
?>
【问题讨论】:
标签: php mysql upload blob thumbnails