您现在的位置是:网站首页> 编程资料编程资料

PHP生成缩略图实例讲解_php实例_

2023-05-25 446人已围观

简介 PHP生成缩略图实例讲解_php实例_

封装的方法函数:

= $scale) { //创建真彩图像资源(imagecreatetruecolor()函数使用GDLibrary创建新的真彩色图像) $newimg = imagecreatetruecolor($thumbWidth, $thumbHeight); //图像处理 imagecopyresampled($newimg, $sourceImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, (($height) * $scale), $height); //以JPEG格式将图像输出到浏览器或文件 ImageJpeg($newimg, $thumbSrc); } //宽度优先 if ($ratio < $scale) { $newimg = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecopyresampled($newimg, $sourceImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, (($width) / $scale)); ImageJpeg($newimg, $thumbSrc); } } else { if ($ratio >= $scale) { $newimg = imagecreatetruecolor($thumbWidth, ($thumbWidth) / $ratio); imagecopyresampled($newimg, $sourceImg, 0, 0, 0, 0, $thumbWidth, ($thumbWidth) / $ratio, $width, $height); ImageJpeg($newimg, $thumbSrc); } if ($ratio < $scale) { $newimg = imagecreatetruecolor(($thumbHeight) * $ratio, $thumbHeight); imagecopyresampled($newimg, $sourceImg, 0, 0, 0, 0, ($thumbHeight) * $ratio, $thumbHeight, $width, $height); ImageJpeg($newimg, $thumbSrc); } } //销毁图像 ImageDestroy($sourceImg); } ?>

调用示例:

到此这篇关于PHP生成缩略图实例讲解的文章就介绍到这了,更多相关PHP生成缩略图内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

-六神源码网