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应用提速面面观
Oct 09 PHP
Discuz 6.0+ 批量注册用户名
Sep 13 PHP
PHP中call_user_func_array()函数的用法演示
Feb 05 PHP
PHP文章采集URL补全函数(FormatUrl)
Aug 02 PHP
关于PHP语言构造器介绍
Jul 08 PHP
PHP生成迅雷、快车、旋风等软件的下载链接代码实例
May 12 PHP
PHP中mysql_field_type()函数用法
Nov 24 PHP
在openSUSE42.1下编译安装PHP7 的方法
Dec 24 PHP
PHP信号量基本用法实例详解
Feb 12 PHP
深入理解PHP JSON数组与对象
Jul 19 PHP
PHP缓存工具XCache安装与使用方法详解
Apr 09 PHP
php实现的简单多进程服务器类完整示例
Feb 01 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
基于mysql的论坛(1)
2006/10/09 PHP
phpmyadmin中配置文件现在需要绝密的短语密码的解决方法
2007/02/11 PHP
PHP输入输出流学习笔记
2015/05/12 PHP
php数字每三位加逗号的功能函数
2015/10/22 PHP
基于PHP代码实现中奖概率算法可用于刮刮卡、大转盘等抽奖算法
2015/12/20 PHP
Zend Framework入门教程之Zend_Config组件用法详解
2016/12/09 PHP
PHP 7.1新特性的汇总介绍
2016/12/16 PHP
Jquery Ajax学习实例4 向WebService发出请求,返回实体对象的异步调用
2010/03/16 Javascript
将input file的选择的文件清空的两种解决方案
2013/10/21 Javascript
两种不同的方法实现js对checkbox进行全选和反选
2014/05/13 Javascript
Javascript 读取操作Sql中的Xml字段
2014/10/09 Javascript
Bootstrap登陆注册页面开发教程
2016/07/12 Javascript
Vue.js一个文件对应一个组件实践
2016/10/27 Javascript
BootStrap Table对前台页面表格的支持实例讲解
2016/12/22 Javascript
JavaScript 函数的定义-调用、注意事项
2017/04/16 Javascript
完美解决axios跨域请求出错的问题
2018/02/05 Javascript
详解JS函数stack size计算方法
2018/06/18 Javascript
详解vue组件中使用路由方法
2019/02/12 Javascript
js获取form表单中name属性的值
2019/02/27 Javascript
vue如何实现自定义底部菜单栏
2019/07/01 Javascript
Vue登录主页动态背景短视频制作
2019/09/21 Javascript
[01:05:36]VP vs TNC Supermajor小组赛B组 BO3 第二场 6.2
2018/06/03 DOTA
Python正则捕获操作示例
2017/08/19 Python
python机器学习之神经网络(三)
2017/12/20 Python
python数据处理 根据颜色对图片进行分类的方法
2018/12/08 Python
numpy库与pandas库axis=0,axis= 1轴的用法详解
2019/05/27 Python
pyspark给dataframe增加新的一列的实现示例
2020/04/24 Python
python 密码学示例——理解哈希(Hash)算法
2020/09/21 Python
英国百年闻名的优质健康产品连锁店:Holland & Barrett
2019/12/19 全球购物
小学老师寄语大全
2014/04/04 职场文书
岗位职责说明书
2014/05/07 职场文书
小学安全工作汇报材料
2014/08/19 职场文书
个人买房协议书范本
2014/10/06 职场文书
检讨书格式
2015/01/23 职场文书
初中语文教学随笔
2015/08/15 职场文书
postgresql无序uuid性能测试及对数据库的影响
2021/06/11 PostgreSQL