我正在创建图像的缩略图,然后将其保存到数据库中,但我不知道该怎么做。这是我的代码
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
$pathToImages = "../uploads/images/";
// open the directory
$dir = opendir( $pathToImages );
// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir( $dir ))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg' )
{
$pathToThumbs = "../uploads/images/thumbs/";
//echo "Creating thumbnail for {$fname} <br />";
// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
// create a new temporary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width,$new_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
$thumbimage = $fname;
}
}
// close the directory
closedir( $dir );
}
createThumbs("/uploads/documents","/uploads/images/thumbs/",100);
缩略图的创建很好,但现在我不知道如何将它保存在数据库中(缺乏技能)