一聚教程网:一个值得你收藏的教程网站

热门教程

超简单php 大图生成缩略图实现代码

时间:2022-06-24 21:07:22 编辑:袖梨 来源:一聚教程网

超简单php教程 大图生成缩略图实现代码

 

/**
* 生成缩略图
*
* @param string $imagepath 图片路径
* @param string $thumb 生成缩略图名称
* @param integer $width 生成缩略图最大宽度
* @param integer $height 生成缩略图最大高度
*

*/
function resizeimage($imagepath, $thumb, $, $)
{
    list($imagewidth, $imageheight) = getimagesize($imagepath);
    $imagepath = imagecreatefromjpeg($imagepath);
    if ($width && ($imagewidth < $imageheight))
    {
        $width = ($height / $imageheight) * $imagewidth;
    }
    else
    {
        $height = ($width / $imagewidth) * $imageheight;
    }
    $image = imagecreatetruecolor($width, $height);
    imagecopyresampled($image, $imagepath, 0, 0, 0, 0, $width, $height, $imagewidth, $imageheight);
    imagepng($image, $thumb);
    imagedestroy($image);
}
resizeimage('test.jpg', 'test_thumb.jpg');
?>

热门栏目