first: get out picture from database.
second: use class like this (only jpeg supported here):
kimage.class.php
<?
class kimage
{
var $thumbHeight=60;
function kimage($args)
{
static $types=array(1=>'gif',2=>'jpg',3=>'png',4=>'swf',5=>'psd',6=>'bmp',7=>'tiff',8=>'tiff-m',9=>'jpc',10=>'jp2',11=>'jpx');
$this->args=$args;
$this->fullPath=$args['path'].'/'.$args['filename'];
$this->thumbPath=$args['thumbs'].'/'.$args['filename'];
if(($info=getimagesize($this->diskPath($this->fullPath)))===NULL)
trigger_error("Error opening image $this->fullPath",E_USER_ERROR);
$this->width=$info[0];
$this->height=$info[1];
$this->type=$types[$info[2]];
$this->tagParms=$info[3];
if(isset($args['thumbHeight']))
$this->thumbHeight=$args['thumbHeight'];
if(isset($args['thumbWidth']))
$this->thumbWidth=$args['thumbWidth'];
else $this->thumbWidth=(int)($this->thumbHeight*$this->width/$this->height+0.5);
}
function diskPath($path)
{
return $this->args['root'].$path;
}
function image()
{
return "<IMG SRC=\"$this->fullPath\" $this->tagParms".(isset($this->args['parms'])?' '.$this->args['parms']:'').'>';
}
function thumbnailExists()
{
$imageFile=$this->diskPath($this->fullPath);
$thumbFile=$this->diskPath($this->thumbPath);
return file_exists($thumbFile) && filemtime($thumbFile)>=filemtime($imageFile);
}
function createThumbnail()
{
static $fun=array();
$imageFile=$this->diskPath($this->fullPath);
$thumbFile=$this->diskPath($this->thumbPath);
if(!$image=@imagecreatefromjpeg($imageFile))
trigger_error("Can't load picture $this->fullPath",E_USER_ERROR);
$thumbnail=ImageCreateTrueColor($this->thumbWidth, $this->thumbHeight);
imageinterlace($thumbnail,1);
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $this->thumbWidth, $this->thumbHeight, $this->width, $this->height);
imagejpeg($thumbnail,$thumbFile);
}
function thumbnail()
{
if(!$this->thumbnailExists())
{
$this->createThumbnail();
}
return "<IMG SRC=\"$this->thumbPath\" WIDTH=\"$this->thumbWidth\" HEIGHT=\"$this->thumbHeight\"".(isset($this->args['parms'])?' '.$this->args['parms']:'').'>';
}
};
?>