Here is the code I did to create a thumbnail image from the database blob field. The trick is to use "imagecreatefromstring()" to create an image file.
Jack Shieh
<?php
require("dbconfig.inc");
$id = $_GET['id'];
if($id) {
$link = @mysql_connect($host, $user, $password) or die("Could not connect: " . mysql_error());
@mysql_select_db($dbname, $link);
$query = "select filetype, image from pictures where id = $id";
$result = @mysql_query($query);
$data = @mysql_result($result,0,"image");
$type = @mysql_result($result,0,"filetype");
Header( "Content-type: $type");
$size = 150; $src = imagecreatefromstring($data);
$width = imagesx($src);
$height = imagesy($src);
$aspect_ratio = $height/$width;
if ($width <= $size) {
$new_w = $width;
$new_h = $height;
} else {
$new_w = $size;
$new_h = abs($new_w * $aspect_ratio);
}
$img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
if ($type == "image/pjpeg") {
imagejpeg($img);
} else if ($type == "image/x-png") {
imagepng($img);
} else if ($type == "image/gif") {
imagegif($img);
}
imagedestroy($img);
mysql_close($link);
};
?>