我现在有一个脚本将在图像内容拉从数据库,并使用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从查询的输出。一切都显得洁净......有人能告诉我什么可能导致这样的行为?任何帮助或指导,不胜感激!

有帮助吗?

解决方案

$ 5说PHP是运行内存。检查你的PHP错误日志。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top