PHP生成缩略图
来源:互联网 发布:《网络基础知识》文档 编辑:程序博客网 时间:2024/06/05 09:57
/** * 生成唯一字符串 * @return string */function getUniName(){return md5(uniqid(microtime(true),true));}/** * 得到文件的扩展名 * @param string $filename * @return string */function getExt($filename){return strtolower(end(explode(".",$filename)));}
/** * 生成缩略图 * @param string $filename * @param string $destination * @param int $dst_w * @param int $dst_h * @param bool $isReservedSource * @param number $scale * @return string */function thumb($filename,$destination=null,$dst_w=null,$dst_h=null,$isReservedSource=true,$scale=0.5){//默认不保留源文件$isReservedSource=falselist($src_w,$src_h,$imagetype)=getimagesize($filename);if(is_null($dst_w)||is_null($dst_h)){$dst_w=ceil($src_w*$scale);$dst_h=ceil($src_h*$scale);}$mime=image_type_to_mime_type($imagetype);//echo $mime;//image/jpeg,image/gif$createFun=str_replace("/", "createfrom", $mime);//imagecreatefromjpeg$outFun=str_replace("/", null, $mime);//imagejpeg$src_image=$createFun($filename);$dst_image=imagecreatetruecolor($dst_w, $dst_h);imagecopyresampled($dst_image, $src_image, 0,0,0,0, $dst_w, $dst_h, $src_w, $src_h);if($destination&&!file_exists(dirname($destination))){mkdir(dirname($destination),0777,true);}$dstFilename=$destination==null?getUniName().".".getExt($filename):$destination;$outFun($dst_image,$dstFilename);imagedestroy($src_image);//销毁资源imagedestroy($dst_image);//销毁资源if(!$isReservedSource){unlink($filename);//删掉源文件}return $dstFilename;}
阅读全文
0 0
- php生成缩略图
- PHP生成图片缩略图
- PHP生成图片缩略图
- PHP批量生成缩略图
- PHP批量生成缩略图
- PHP批量生成缩略图
- PHP图片生成缩略图
- PHP生成图片缩略图
- php 生成缩略图
- PHP 生成缩略图类
- PHP 生成图片缩略图
- php生成缩略图类
- 生成缩略图PHP
- PHP生成图片缩略图
- Php生成缩略图
- php生成缩略图
- PHP缩略图的生成
- PHP 生成图片缩略图
- Java读取图像metadata信息
- vue 分页组件及props传参
- java分层架构中各层级的调用关系
- Dijkstra+堆优化模板
- POJ1330Nearest Common Ancestors
- PHP生成缩略图
- QT问题系列(2)
- Beaglebone Black上使用Codesys开发EtherCAT(四)
- 斐波那契数列数列的三种时间复杂度的实现方法
- API学习Collections
- HDU2586How far away? LCA
- 数据库数据按指定格式导出到Excel
- 大学生活随笔
- <iframe>引用页面传值获取不到的问题