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学习 函数 课件
Jun 15 PHP
PHP 获取远程网页内容的代码(fopen,curl已测)
Jun 06 PHP
深入for,while,foreach遍历时间比较的详解
Jun 08 PHP
解决Codeigniter不能上传rar和zip压缩包问题
Mar 07 PHP
php计算几分钟前、几小时前、几天前的几个函数、类分享
Apr 09 PHP
php格式化时间戳显示友好的时间实现思路及代码
Oct 23 PHP
PHP中使用Imagick操作PSD文件实例
Jan 26 PHP
php中strtotime函数性能分析
Nov 20 PHP
PHP执行shell脚本运行程序不产生core文件的方法
Dec 28 PHP
PHP批量删除jQuery操作
Jul 23 PHP
微信支付之JSAPI公众号支付详解
May 15 PHP
Laravel 在views中加载公共页面的实现代码
Oct 22 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 过滤英文标点符号及过滤中文标点符号代码
2014/06/12 PHP
php模拟登陆的实现方法分析
2015/01/09 PHP
yii2实现根据时间搜索的方法
2016/05/25 PHP
js的表单操作 简单计算器
2011/12/29 Javascript
jquery实现checkbox 全选/全不选的通用写法
2014/02/22 Javascript
单击某一段文字改写文本颜色
2014/06/06 Javascript
javascript中eval和with用法实例总结
2015/11/30 Javascript
浏览器环境下JavaScript脚本加载与执行探析之动态脚本与Ajax脚本注入
2016/01/19 Javascript
使用do...while的方法输入一个月中所有的周日(实例代码)
2016/07/22 Javascript
微信小程序开发实战教程之手势解锁
2016/11/18 Javascript
vue-cli项目优化方法- 缩短首屏加载时间
2018/04/01 Javascript
Vue实现自定义下拉菜单功能
2018/07/16 Javascript
Vue 中的受控与非受控组件的实现
2018/12/17 Javascript
浅谈Vue项目骨架屏注入实践
2019/08/05 Javascript
ES6中Symbol、Set和Map用法详解
2019/08/20 Javascript
Vue+Java 通过websocket实现服务器与客户端双向通信操作
2020/09/22 Javascript
python函数缺省值与引用学习笔记分享
2013/02/10 Python
python新手经常遇到的17个错误分析
2014/07/30 Python
Python利用公共键如何对字典列表进行排序详解
2018/05/19 Python
Python实现的字典排序操作示例【按键名key与键值value排序】
2018/12/21 Python
Python+OpenCV实现实时眼动追踪的示例代码
2019/11/11 Python
关于TensorFlow新旧版本函数接口变化详解
2020/02/10 Python
HTML5+CSS3网页加载进度条的实现,下载进度条的代码实例
2016/12/30 HTML / CSS
HTML5 canvas画图并保存成图片的jcanvas插件
2014/01/17 HTML / CSS
HTML5 Canvas中使用用路径描画圆弧
2015/01/01 HTML / CSS
英国打印机墨水和碳粉商店:Printerinks
2017/06/30 全球购物
单位个人查摆问题及整改措施
2014/10/28 职场文书
社区学习党的群众路线教育实践活动心得体会
2014/11/03 职场文书
2014年文员工作总结
2014/11/18 职场文书
高三英语教学计划
2015/01/23 职场文书
六一文艺汇演开幕词
2015/01/29 职场文书
党员学习型组织心得体会
2019/06/21 职场文书
最美劳动诗,致敬所有的劳动者!
2019/07/12 职场文书
导游词之京东大峡谷旅游区
2019/10/29 职场文书
如何用python清洗文件中的数据
2021/06/18 Python
nginx日志格式分析和修改
2022/04/28 Servers