Home  >  Article  >  Backend Development  >  Super simple PHP large image generation thumbnail implementation code_PHP tutorial

Super simple PHP large image generation thumbnail implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:46:01789browse

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

 

/**
* Generate thumbnails
*
* @param string $imagepath image path
* @param string $thumb Generate thumbnail name
* @param integer $width Maximum width of generated thumbnail
* @param integer $height The maximum height of generated thumbnail
*

*/
function resizeimage($imagepath, $thumb, $width = 200, $height = 200)
{
    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');
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632983.htmlTechArticle超简单php教程 大图生成缩略图实现代码 ?php /** * 生成缩略图 * * @param string $imagepath 图片路径 * @param string $thumb 生成缩略图名称 * @param inte...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn