
php教程--案例23(生成缩略图)
发布日期:2021-05-06 21:10:28
浏览次数:16
分类:精选文章
本文共 1853 字,大约阅读时间需要 6 分钟。
234,'name'=>'王五');?>0) { $error_msg = '上传错误:'; switch ($pic_info['error']) { case 1: $error_msg .= '文件大小超过了php配置文件中upload_max_filesize选项的限制值'; break; case 2: $error_msg .= '文件大小超过了表单中max_file选项的值'; break; case 3: $error_msg .= '文件只有部分被上传'; break; case 4: $error_msg .= '没有文件被上传'; break; case 6: $error_msg .= '找不到临时文件夹'; break; case 7: $error_msg .= '文件写入失败!'; break; default: $error_msg .= '未知错误'; break; } die($error_msg); } $type = substr(strrchr($pic_info['name'],'.'),1); if ($type !== 'jpg') { die('图像类型不符合要求,允许的类型为:jpg'); } //获得图片尺寸 $img_info = getimagesize($pic_info['tmp_name']); //获得图片宽 $width = $img_info[0]; //获得图片高 $height = $img_info[1]; echo "width=$width,height=$height"; echo ""; $max_width = $max_height = 90; $new_width = $new_height = 60; //判断宽大于高 if($width > $height) { $new_width = $max_width; $new_height = round($new_width * $height / $width); } else { $new_height = $max_height; $new_width = round($new_height * $width / $height); } echo "new_width=$new_width,new_height=$new_height"; //创建画布 $thumb = imagecreatetruecolor($new_width,$new_height); //源图 $source = imagecreatefromjpeg($pic_info['tmp_name']); //复制图 imagecopyresized($thumb,$source,0,0,0,0,$new_width,$new_height,$width,$height); $new1 = './img/'.$info['id'].'.jpg'; //保存图片 imagejpeg($thumb,$new1,100);}?>用户头像上传
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月26日 23时36分27秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
linux c 正则
2023-01-31
Linux C/C++ 学习路线(已拿腾讯、百度 offer)
2023-01-31
Linux cat 命令的进化版:Bat 0.25 正式发布,行压缩功能亮点十足!
2023-01-31
linux centos tomcat8配置apr模式
2023-01-31
linux centos 安装 docker-compose 1.27.4
2023-01-31
linux centos6.4 php连接sql server2008
2023-01-31
Linux Centos7 xfsdump文件系统的备份和恢复
2023-01-31
Linux centos7 防火墙设置
2023-01-31
linux centos下 svn 版本控制服务器的搭建
2023-01-31
Linux CFSSL 生成证书
2023-01-31
linux chrom 系统无法读取用户偏好配置无需删除.config配置文件
2023-01-31
linux cmd using
2023-01-31
linux coreseek-4.1安装
2023-01-31
linux core文件设置
2023-01-31
Linux CPU优化性能实战
2023-01-31
Linux CPU管理及监控与性能评估
2023-01-31
Linux CPU负载状态分析实战
2023-01-31
Linux Crontab
2023-01-31
linux crontab 实现每秒执行
2023-01-31
linux crw权限,linux中crw brw lrw等等文件属性是什么
2023-01-31