网页标准化设计使用的优势
- 时间:
- 地点:
2023最新开源城市站群cms系统【万站巅云站群CMS系统源码程序】
精美大气网络公司网站模板,网络公司网站源码,专业网络公司网页设计
西部数码代理平台模板 -西部数码代理价格自动获取
最新一键建站系统源码,saas建站系统源码,自助建站整站源码,站长源码,自助建站系统源码,源码搭建教程,开源自助建站系统,php智能建站系统,可视化网站框架源码
最新首发自助建站系统源码,傻瓜式一键建站系统源码,高度开源支持专业在线自助建站服务平台搭建
巅云拖拽式VUE前端框架4.0,可视化拖拽编辑器,实现了h5可视化拖拽生成工具,前端大屏布局,组件化模板机制
封装的方法函数:
<?php /** * 生成缩略图 * $imgSrc 图片源路径 * $thumbWidth 缩略图宽度 * $thumbHeight 缩略图高度 * $thumbSrc 缩略图路径 * $isCut 是否剪切图片 */ function createThumbImg($imgSrc, $thumbWidth, $thumbHeight, $thumbSrc, $isCut = false) { //1.获取图片的类型 $type = substr(strrchr($imgSrc, "."), 1); //2.初始化图象 if ($type == "jpg" || $type == "jpeg") { //创建一块画布,并从JPEG文件或URL地址载入一副图像 $sourceImg = imagecreatefromjpeg($imgSrc); }elseif ($type == "gif") { //创建一块画布,并从GIF文件或URL地址载入一副图像 $sourceImg = imagecreatefromgif($imgSrc); }elseif ($type == "png") { //创建一块画布,并从PNG文件或URL地址载入一副图像 $sourceImg = imagecreatefrompng($imgSrc); } elseif ($type == "wbmp") { //创建一块画布,并从WBMP文件或URL地址载入一副图像 $sourceImg = imagecreatefromwbmp($imgSrc); } //取得图像宽度 $width = imagesx($sourceImg); //取得图像高度 $height = imagesy($sourceImg); //3.生成图象 //缩略图的图象比例 $scale = ($thumbWidth) / ($thumbHeight); //源图片的图象比例 $ratio = ($width) / ($height); if (($isCut) == 1) { //高度优先 if ($ratio >= $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 //图片源路径 $imgSrc="D:/PHP/test/demo.jpg"; //缩略图路径 $thumbSrc="D:/PHP/test/thumb.jpg"; createThumbImg($path,100,100,$thumbSrc); ?>
到此这篇关于PHP生成缩略图实例讲解的文章就介绍到这了,更多相关PHP生成缩略图内容请搜索IT博客社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT博客社区!
notmore
联系我们
合作或咨询可通过如下方式:
QQ/微信:123456
网址:www.xxxx.cn
微信公众号:车展门票
关于本站
Copyright 车展网 www.xxxx.cn Reserved渝ICP备xxxxxxxx号
关注我们