2009-08-12 34 views
1

數據庫目前,我有一個腳本,將在圖像內容拉從一個數據庫,並使用createimagefromstring()調整大小,返回一個調整(重採樣)圖像顯示:圖像從PHP

$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像素)的圖像時,它將存儲在數據庫中,但腳本不顯示重新採樣的圖像。

爲了排除故障,我檢查了db以及print_r'd查詢的輸出。一切似乎都是猶太教......有人能告訴我什麼可能導致這種行爲?任何幫助或指導,非常感謝!

回答

2

$ 5表示php內存不足。檢查你的PHP錯誤日誌。

+0

非常感謝。如果我有,我會付錢的。 :) – 2009-08-13 02:30:45