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 相关文章推荐
Extended CHM PHP 语法手册之 DIY
Oct 09 PHP
使用 php4 加速 web 传输
Oct 09 PHP
smarty+adodb+部分自定义类的php开发模式
Dec 31 PHP
php下使用以下代码连接并测试
Apr 09 PHP
PHP 中关于ord($str)&amp;gt;0x80的详细说明
Sep 23 PHP
PHP实现自动识别Restful API的返回内容类型
Feb 07 PHP
PHP下载远程文件到本地存储的方法
Mar 24 PHP
Laravel 5框架学习之子视图和表单复用
Apr 09 PHP
为你总结一些php信息函数
Oct 21 PHP
PHP翻页跳转功能实现方法
Nov 30 PHP
Laravel 5.5基于内置的Auth模块实现前后台登陆详解
Dec 21 PHP
PHP 实现缩略图
Mar 09 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代码
2008/04/07 PHP
setcookie中Cannot modify header information-headers already sent by错误的解决方法详解
2013/05/08 PHP
json的键名为数字时的调用方式(示例代码)
2013/11/15 PHP
详细解读php的命名空间(二)
2018/02/21 PHP
php数组和链表的区别总结
2019/09/20 PHP
javascript json 新手入门文档
2009/12/03 Javascript
写JQuery插件的基本知识
2013/11/25 Javascript
js鼠标及对象坐标控制属性详细解析
2013/12/14 Javascript
IE与FireFox的JavaScript兼容问题解决办法
2013/12/31 Javascript
js利用事件的阻止冒泡实现点击空白模态框的隐藏
2014/01/24 Javascript
5个可以帮你理解JavaScript核心闭包和作用域的小例子
2014/10/08 Javascript
node-http-proxy修改响应结果实例代码
2016/06/06 Javascript
JS中判断null的方法分析
2016/11/21 Javascript
JQuery和PHP结合实现动态进度条上传显示
2016/11/23 Javascript
使用BootStrap建立响应式网页——通栏轮播图(carousel)
2016/12/21 Javascript
js 事件的传播机制(实例讲解)
2017/07/20 Javascript
微信小程序实现倒计时60s获取验证码
2020/04/17 Javascript
ES6 Promise对象概念及用法实例详解
2019/10/15 Javascript
[02:30]辉夜杯主赛事第二日胜者组半决赛 CDEC.Y赛后采访
2015/12/26 DOTA
用python写asp详细讲解
2013/12/16 Python
Python中的jquery PyQuery库使用小结
2014/05/13 Python
浅析python 中__name__ = '__main__' 的作用
2014/07/05 Python
利用Python命令行传递实例化对象的方法
2016/11/02 Python
ActiveMQ:使用Python访问ActiveMQ的方法
2019/01/30 Python
华为2019校招笔试题之处理字符串(python版)
2019/06/25 Python
python字符串切割:str.split()与re.split()的对比分析
2019/07/16 Python
Python如何使用队列方式实现多线程爬虫
2020/05/12 Python
为您搜罗全球潮流時尚品牌:HBX
2019/12/04 全球购物
Shell如何接收变量输入
2012/09/24 面试题
阿德的梦教学反思
2014/02/06 职场文书
测控技术自荐信
2014/06/05 职场文书
城市规划应届毕业生自荐信
2014/07/04 职场文书
2014广电局实施党的群众路线教育实践活动方案思想汇报
2014/09/22 职场文书
2014年维修工作总结
2014/11/22 职场文书
企业承诺书格式范文
2015/04/28 职场文书
Python中threading库实现线程锁与释放锁
2021/05/17 Python