私は現在、データベースから画像コンテンツを取得し、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);
現在、このスクリプトはほとんどのサムネイルで機能し、必要に応じて画面に表示されます。ただし、1000px を超える幅の広い画像をアップロードすると、データベースに保存されますが、スクリプトはリサンプリングされた画像を表示しません。
トラブルシューティングのために、データベースをチェックし、クエリからの出力を print_r しました。すべてがコーシャのようです... 誰かがそのような行動を引き起こしている可能性があるものを教えてもらえますか? どんな助けや指導も大歓迎です!