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 会话(session 时间设定)使用入门代码
Jun 05 PHP
php读取csv文件后,uft8 bom导致在页面上显示出现问题的解决方法
Aug 10 PHP
PHP中设置一个严格30分钟过期Session面试题的4种答案
Jul 30 PHP
php中字符集转换iconv函数使用总结
Oct 11 PHP
php中socket的用法详解
Oct 24 PHP
PHP根据两点间的经纬度计算距离
Oct 31 PHP
php中使用key,value,current,next和prev函数遍历数组的方法
Mar 17 PHP
深入剖析浏览器退出之后php还会继续执行么
May 17 PHP
thinkPHP中session()方法用法详解
Dec 08 PHP
PHP基于PDO实现的SQLite操作类【包含增删改查及事务等操作】
Jun 21 PHP
laravel如何开启跨域功能示例详解
Aug 31 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
[EPIC] Larva vs Flash ZvT @ Crossing Field [2017-10-09]
2020/03/17 星际争霸
PHP 和 COM
2006/10/09 PHP
php获取网页内容方法总结
2008/12/04 PHP
php版小黄鸡simsimi聊天机器人接口分享
2014/01/26 PHP
ThinkPHP3.1基础知识快速入门
2014/06/19 PHP
PHP+jQuery 注册模块的改进(三):更新到Smarty3.1
2014/10/14 PHP
php类的自动加载操作实例详解
2016/09/28 PHP
PHP simplexml_load_file()函数讲解
2019/02/03 PHP
PHP+MySQL实现在线测试答题实例
2020/01/02 PHP
PHP+ajax实现上传、删除、修改单张图片及后台处理逻辑操作详解
2020/02/12 PHP
ASP中进行HTML数据及JS数据编码函数
2009/11/11 Javascript
JS+CSS制作DIV层可(最小化/拖拽/排序)功能实现代码
2013/02/25 Javascript
js简单的表格添加行和删除行操作示例
2014/03/31 Javascript
jQuery中:first-child选择器用法实例
2014/12/31 Javascript
基于jQuery.Hz2Py.js插件实现的汉字转拼音特效
2015/05/07 Javascript
基于Jquery实现焦点图淡出淡入效果
2015/11/30 Javascript
同步文本框内容JS代码实现
2016/08/04 Javascript
详解springmvc 接收json对象的两种方式
2016/12/06 Javascript
分分钟玩转Vue.js组件(二)
2017/03/01 Javascript
JS实现的二叉树算法完整实例
2017/04/06 Javascript
Vue实现拖放排序功能的实例代码
2019/07/08 Javascript
解决vue数据不实时更新的问题(数据更改了,但数据不实时更新)
2020/10/27 Javascript
python解决pandas处理缺失值为空字符串的问题
2018/04/08 Python
Python 操作 ElasticSearch的完整代码
2019/08/04 Python
python numpy 常用随机数的产生方法的实现
2019/08/21 Python
Python多线程通信queue队列用法实例分析
2020/03/24 Python
Wiggle中国:英国骑行、跑步、游泳 & 铁三运动装备专卖网店
2016/08/02 全球购物
中学实习教师自我鉴定
2013/12/12 职场文书
工作决心书
2014/03/11 职场文书
家长对孩子的评语
2014/04/18 职场文书
协议书怎么写
2014/04/21 职场文书
基层党员公开承诺书
2014/05/29 职场文书
2014年全国爱牙日宣传活动方案
2014/09/21 职场文书
村主任“四风”问题个人整改措施
2014/10/04 职场文书
父亲节寄语大全
2015/02/27 职场文书
Linux中sftp常用命令整理
2022/06/28 Servers