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 开源框架22个简单简介
Aug 24 PHP
php 无法载入mysql扩展
Mar 12 PHP
让PHP更快的提供文件下载的代码
Jun 13 PHP
PHP改进计算字符串相似度的函数similar_text()、levenshtein()
Oct 27 PHP
js+php实现静态页面实时调用用户登陆状态的方法
Jan 04 PHP
PHP实现事件机制的方法
Jul 10 PHP
PHP简单实现断点续传下载的方法
Sep 25 PHP
php实现网站文件批量压缩下载功能
Oct 28 PHP
php经典算法集锦
Nov 14 PHP
php实现购物车产品删除功能(2)
Jul 23 PHP
PHP中的empty、isset、isnull的区别与使用实例
Mar 22 PHP
PHP实现chrome表单请求数据转换为接口使用的json数据
Mar 04 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封装XML和JSON格式数据接口操作示例
2019/03/06 PHP
laravel框架使用FormRequest进行表单验证,验证异常返回JSON操作示例
2020/02/18 PHP
Firefox中beforeunload事件的实现缺陷浅析
2012/05/03 Javascript
jQuery判断checkbox是否选中的3种方法
2014/08/12 Javascript
Linux下使用jq友好的打印JSON技巧分享
2014/11/18 Javascript
JavaScript实现按照指定长度为数字前面补零输出的方法
2015/03/19 Javascript
如何改进javascript代码的性能
2015/04/02 Javascript
AngularJS使用angular-formly进行表单验证
2015/12/27 Javascript
快速使用Bootstrap搭建传送带
2016/05/06 Javascript
jQuery获取radio选中项的值实例
2016/06/18 Javascript
Bootstrap栅格系统学习笔记
2016/11/25 Javascript
JavaScript实现星星等级评价功能
2017/03/22 Javascript
JavaScript中清空数组的三种方式
2017/03/22 Javascript
jQuery制作全屏宽度固定高度轮播图(实例讲解)
2017/07/08 jQuery
JS中正则表达式要注意lastIndex属性
2017/08/08 Javascript
vue-cli中的webpack配置详解
2017/09/25 Javascript
无限循环轮播图之运动框架(原生JS实现)
2017/10/01 Javascript
vue中的计算属性的使用和vue实例的方法示例
2017/12/04 Javascript
手把手教你用Node.js爬虫爬取网站数据的方法
2018/07/05 Javascript
[59:53]DOTA2-DPC中国联赛 正赛 VG vs Elephant BO3 第二场 3月6日
2021/03/11 DOTA
Python中线程编程之threading模块的使用详解
2015/06/23 Python
Python上传package到Pypi(代码简单)
2016/02/06 Python
Python做文本按行去重的实现方法
2016/10/19 Python
python机器学习实战之树回归详解
2017/12/20 Python
解读python如何实现决策树算法
2018/10/11 Python
python实现小球弹跳效果
2019/05/10 Python
python调用接口的4种方式代码实例
2019/11/19 Python
Django 解决由save方法引发的错误
2020/05/21 Python
使用Dajngo 通过代码添加xadmin用户和权限(组)
2020/07/03 Python
HTML5 canvas基本绘图之绘制曲线
2016/06/27 HTML / CSS
德国汉莎航空中国官网: Lufthansa中国
2017/03/30 全球购物
TUMI香港官网:国际领先的行李箱、背囊品牌
2021/03/01 全球购物
港湾网络笔试题
2014/04/19 面试题
应届大学生自荐信
2013/12/05 职场文书
酒店营销策划方案
2014/02/07 职场文书
一次SQL查询优化原理分析(900W+数据从17s到300ms)
2022/06/10 SQL Server