0

我目前有一个脚本,它将从数据库中提取图像内容,并使用 createimagefromstring() 返回一个调整大小(重新采样)的图像以供显示:

$max_width = 170;

// Get the image

@mysql_connect('host', 'user', 'pass');
@mysql_select_db('db');

$query = "SELECT `thumbnail_contents`, `thumbnail_mimetype` FROM `videos` WHERE video_number  = '$video_number'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_object($result);

// Resize if pic bigger than $max_width
// Set the header
header('Content-type:' . $row->thumbnail_mimetype);

// Get original size of image
$image = imagecreatefromstring($row->thumbnail_contents);
$current_width = imagesx($image);
$current_height = imagesy($image);

// Set thumbnail width
$widths = array($current_width, $max_width);
$new_width = min($widths);

// Calculate thumbnail height from given width to maintain ratio
$new_height = $current_height / $current_width*$new_width;

// Create new image using thumbnail sizes
$thumb = imagecreatetruecolor($new_width,$new_height);

// Copy original image to thumbnail
imagecopyresampled($thumb,$image,0,0,0,0,$new_width,$new_height,imagesx($image),imagesy($image));

// Show thumbnail on screen
$show = imagejpeg($thumb);

// Clean memory
imagedestroy($image);
imagedestroy($thumb);

目前,此脚本适用于大多数缩略图,并根据需要在屏幕上显示它们。但是,当我上传一个高宽度的图像时,比如超过 1000 像素,它会存储在数据库中,但脚本不会显示重新采样的图像。

为了排除故障,我检查了数据库,以及 print_r'd 查询的输出。一切似乎都是犹太洁食......有人可以告诉我可能导致这种行为的原因吗?非常感谢任何帮助或指导!

4

1 回答 1

1

$5 表示 php 内存不足。检查您的 php 错误日志。

于 2009-08-12T22:26:35.420 回答