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 相关文章推荐
解决MySQL中文输出变成问号的问题
Jun 05 PHP
PHP的一个基础知识 表单提交
Jul 04 PHP
PHP 常用数组内部函数(Array Functions)介绍
Jun 05 PHP
PHP include任意文件或URL介绍
Apr 29 PHP
PHP中echo和print的区别
Aug 28 PHP
php实现的微信红包算法分析(非官方)
Sep 25 PHP
PHP获取指定日期是星期几的实现方法
Nov 30 PHP
php 反斜杠处理函数addslashes()和stripslashes()实例详解
Dec 25 PHP
PHP微信模板消息操作示例
Jun 29 PHP
Laravel5.5以下版本中如何自定义日志行为详解
Aug 01 PHP
Laravel第三方包报class not found的解决方法
Oct 13 PHP
PHP设计模式(五)适配器模式Adapter实例详解【结构型】
May 02 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
7个超级实用的PHP代码片段
2011/07/11 PHP
php时间函数用法分析
2016/05/28 PHP
jquery 最简单易用的表单验证插件
2010/02/27 Javascript
jQuery 顺便学习下CSS选择器 奇偶匹配nth-child(even)
2010/05/24 Javascript
javascript设计模式 封装和信息隐藏(上)
2012/07/24 Javascript
javascript检查表单数据是否改变的方法
2013/07/30 Javascript
node.js中的fs.symlinkSync方法使用说明
2014/12/15 Javascript
Javascript实现获取及设置光标位置的方法
2015/07/21 Javascript
js自定义回调函数
2015/12/13 Javascript
一起学写js Calender日历控件
2016/04/14 Javascript
js操作数据库实现注册和登陆的简单实例
2016/05/26 Javascript
谈谈第三方App接入微信登录 解读
2016/12/27 Javascript
微信小程序搜索组件wxSearch实例详解
2017/06/08 Javascript
解决百度Echarts图表坐标轴越界的方法
2018/10/17 Javascript
vue中通过使用$attrs实现组件之间的数据传递功能
2019/09/01 Javascript
python网络编程学习笔记(九):数据库客户端 DB-API
2014/06/09 Python
Mac下Supervisor进程监控管理工具的安装与配置
2014/12/16 Python
深入理解Javascript中的this关键字
2015/03/27 Python
在Python中用has_key()方法查找键是否存在的教程
2015/05/21 Python
Python3数据库操作包pymysql的操作方法
2018/07/16 Python
Python字符串内置函数功能与用法总结
2019/04/16 Python
py-charm延长试用期限实例
2019/12/22 Python
python 使用raw socket进行TCP SYN扫描实例
2020/05/05 Python
Hotels.com泰国:酒店预订网站
2019/11/20 全球购物
公司财务工作总结的自我评价
2013/11/23 职场文书
骨干教师培训制度
2014/01/13 职场文书
办理生育手续介绍信
2014/01/14 职场文书
幼儿园教师工作感言
2014/02/15 职场文书
《小小竹排画中游》教学反思
2014/02/26 职场文书
知名企业招聘广告词大全
2014/03/18 职场文书
中药学专业求职信
2014/05/31 职场文书
2014年销售部工作总结
2014/12/01 职场文书
投资意向协议书
2015/01/29 职场文书
中学团支部工作总结
2015/08/13 职场文书
新员工实习期个人工作总结
2015/10/15 职场文书
2016年植树节红领巾广播稿
2015/12/17 职场文书