php修改上传图片尺寸的方法


Posted in PHP onApril 14, 2015

本文实例讲述了php修改上传图片尺寸的方法。分享给大家供大家参考。具体实现方法如下:

<?php
// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=600;
$newheight=($height/$width)*600;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "images/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);
imagedestroy($src);
imagedestroy($tmp);
// NOTE: PHP will clean up the temp file it created when the request
// has completed.
?>

希望本文所述对大家的php程序设计有所帮助。

PHP 相关文章推荐
如何跨站抓取别的站点的页面的补充
Oct 09 PHP
PHP数组内存耗用太多问题的解决方法
Apr 05 PHP
PHP校验ISBN码的函数代码
Jan 17 PHP
小谈php正则提取图片地址
Mar 27 PHP
php备份数据库类分享
Apr 14 PHP
PHP实现的网站目录扫描索引工具
Sep 08 PHP
浅谈使用 Yii2 AssetBundle 中 $publishOptions 的正确姿势
Nov 08 PHP
PHP ADODB实现事务处理功能示例
May 25 PHP
php实现微信分享朋友链接功能
Feb 18 PHP
laravel框架模型、视图与控制器简单操作示例
Oct 10 PHP
Laravel5.1 框架响应基本用法实例分析
Jan 04 PHP
通过PHP实现用户注册后邮箱验证激活
Nov 10 PHP
php动态添加url查询参数的方法
Apr 14 #PHP
php保存任意网络图片到服务器的方法
Apr 14 #PHP
php实现改变图片直接打开为下载的方法
Apr 14 #PHP
php计算到指定日期还有多少天的方法
Apr 14 #PHP
php返回相对时间(如:20分钟前,3天前)的方法
Apr 14 #PHP
php备份数据库类分享
Apr 14 #PHP
PHP用反撇号执行外部命令
Apr 14 #PHP
You might like
创建数据库php代码 用PHP写出自己的BLOG系统
2010/04/12 PHP
PHP学习笔记之一
2011/01/17 PHP
php生成百度sitemap站点地图类函数实例
2014/10/17 PHP
php自动更新版权信息显示的方法
2015/06/19 PHP
php array_map使用自定义的函数处理数组中的每个值
2016/10/26 PHP
PHP中define() 与 const定义常量的区别详解
2019/06/25 PHP
phpstorm激活码2020附使用详细教程
2020/09/25 PHP
jquery CSS选择器笔记
2010/03/29 Javascript
jQuery1.4.2与老版本json格式兼容的解决方法
2011/02/12 Javascript
从零开始学习jQuery (三) 管理jQuery包装集
2011/02/23 Javascript
JavaScript中的字符串操作详解
2013/11/12 Javascript
jQuery鼠标悬浮链接弹出跟随图片实例代码
2016/01/08 Javascript
原生JavaScript实现动态省市县三级联动下拉框菜单实例代码
2016/02/03 Javascript
jQuery DateTimePicker 日期和时间插件示例
2017/01/22 Javascript
原生JavaScript实现的简单省市县三级联动功能示例
2017/05/27 Javascript
Vue2.0 axios前后端登陆拦截器(实例讲解)
2017/10/27 Javascript
vue仿淘宝订单状态的tab切换效果
2020/06/23 Javascript
利用vue重构有赞商城的思路以及总结整理
2019/02/21 Javascript
vue项目实现图片上传功能
2019/12/23 Javascript
JavaScript Window窗口对象属性和使用方法
2020/01/19 Javascript
[02:04]2018DOTA2亚洲邀请赛Secret赛前采访
2018/04/03 DOTA
PyQt5每天必学之关闭窗口
2018/04/19 Python
uwsgi+nginx部署Django项目操作示例
2018/12/04 Python
Python 做曲线拟合和求积分的方法
2018/12/29 Python
Django JWT Token RestfulAPI用户认证详解
2019/01/23 Python
python 调用pyautogui 实时获取鼠标的位置、移动鼠标的方法
2019/08/27 Python
Django框架 信号调度原理解析
2019/09/04 Python
解决pycharm中导入自己写的.py函数出错问题
2020/02/12 Python
解决Python发送Http请求时,中文乱码的问题
2020/04/30 Python
canvas学习总结三之绘制路径-线段
2019/01/31 HTML / CSS
会计电算化个人自我评价
2013/11/17 职场文书
好学生评语大全
2014/05/05 职场文书
部门年终奖分配方案
2014/05/07 职场文书
低碳环保标语
2014/06/12 职场文书
六查六看心得体会
2014/10/14 职场文书
Python数据分析入门之数据读取与存储
2021/05/13 Python