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 相关文章推荐
php in_array 函数使用说明与in_array需要注意的地方说明
Apr 13 PHP
php下使用strpos需要注意 === 运算符
Jul 17 PHP
php中文验证码实现示例分享
Jan 12 PHP
yii框架配置默认controller和action示例
Apr 30 PHP
PHP使用CURL实现对带有验证码的网站进行模拟登录的方法
Jul 23 PHP
php调用mysql存储过程实例分析
Dec 29 PHP
4种PHP异步执行的常用方式
Dec 24 PHP
PHP通过微信跳转的Code参数获取用户的openid(关键代码)
Jul 06 PHP
PHP实现对xml的增删改查操作案例分析
May 19 PHP
PHP实现微信小程序人脸识别刷脸登录功能
May 24 PHP
thinkphp5引入公共部分header、footer的方法详解
Sep 14 PHP
浅谈laravel 5.6 安装 windows上使用composer的安装过程
Oct 18 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
Get或Post提交值的非法数据处理
2006/10/09 PHP
解析php安全性问题中的:Null 字符问题
2013/06/21 PHP
Yii中使用PHPExcel导出Excel的方法
2014/12/26 PHP
php实现的mongodb操作类
2015/05/28 PHP
php微信高级接口调用方法(自定义菜单接口、客服接口、二维码)
2016/11/28 PHP
在laravel中使用with实现动态添加where条件
2019/10/10 PHP
thinkphp 5框架实现登陆,登出及session登陆状态检测功能示例
2019/10/10 PHP
Laravel 类和接口注入相关的代码
2019/10/15 PHP
初学js插入节点appendChild insertBefore使用方法
2011/07/04 Javascript
如何用JavaScript动态呼叫函数(两种方式)
2013/05/03 Javascript
点击表单提交时出现jQuery没有权限的解决方法
2014/07/23 Javascript
DEDECMS如何为文章添加HOT NEW标志图片
2015/08/14 Javascript
javascript函数式编程程序员的工具集
2015/10/11 Javascript
jquery实现下拉框功能效果【实例代码】
2016/05/06 Javascript
详解在React里使用&quot;Vuex&quot;
2018/04/02 Javascript
Python操作MongoDB数据库PyMongo库使用方法
2015/04/27 Python
浅谈python中的变量默认是什么类型
2016/09/11 Python
Python输入二维数组方法
2018/04/13 Python
python爬虫框架scrapy实现模拟登录操作示例
2018/08/02 Python
Python3利用print输出带颜色的彩色字体示例代码
2019/04/08 Python
Python实现的企业粉丝抽奖功能示例
2019/07/26 Python
python中图像通道分离与合并实例
2020/01/17 Python
python数据预处理方式 :数据降维
2020/02/24 Python
用于ETL的Python数据转换工具详解
2020/07/21 Python
Python selenium键盘鼠标事件实现过程详解
2020/07/28 Python
一个非常简单好用的Python图形界面库(PysimpleGUI)
2020/12/28 Python
Python使用Turtle模块绘制国旗的方法示例
2021/02/28 Python
世界最大的海报和艺术印刷商店:AllPosters.com
2017/02/01 全球购物
英国足球店:UK Soccer Shop
2017/11/19 全球购物
俄罗斯大型在线书店:Читай-город
2019/10/10 全球购物
汽车运用工程毕业生自荐信
2013/10/29 职场文书
优秀大学生的自我评价
2014/01/16 职场文书
松材线虫病防治方案
2014/06/15 职场文书
2015年世界环境日活动总结
2015/02/11 职场文书
聘任书的格式及模板
2019/10/28 职场文书
CSS SandBox应用场景及常见问题
2022/06/25 HTML / CSS