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
PHP Session_Regenerate_ID函数双释放内存破坏漏洞
Jan 27 PHP
PHP源代码数组统计count分析
Aug 02 PHP
奇怪的PHP引用效率问题分析
Mar 23 PHP
关于更改Zend Studio/Eclipse代码风格主题的介绍
Jun 23 PHP
php解析json数据实例
Aug 19 PHP
php生成二维码时出现中文乱码的解决方法
Dec 18 PHP
PHP实现远程下载文件到本地
May 17 PHP
PHP查找与搜索数组元素方法总结
Jun 12 PHP
PHP-FPM之Chroot执行环境详解
Aug 03 PHP
实例讲解php数据访问
May 09 PHP
Laravel5.4框架中视图共享数据的方法详解
Sep 05 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之生成GIF动画的实现方法
2013/06/07 PHP
PHP实现一维数组与二维数组去重功能示例
2018/05/24 PHP
PHP时间处理类操作示例
2018/09/05 PHP
PHP 加密 Password Hashing API基础知识点
2020/03/02 PHP
TP5框架页面跳转样式操作示例
2020/04/05 PHP
JQUERY的属性选择符和自定义选择符使用方法(二)
2011/04/07 Javascript
Jquery+ajax+JAVA(servlet)实现下拉菜单异步取值
2016/03/23 Javascript
javascript面向对象程序设计高级特性经典教程(值得收藏)
2016/05/19 Javascript
bootstrap警告框使用方法解析
2017/01/13 Javascript
Vue计算属性的学习笔记
2017/03/22 Javascript
AngularJs返回前一页面时刷新一次前面页面的方法
2018/10/09 Javascript
JavaScript根据json生成html表格的示例代码
2018/10/24 Javascript
详解Vue源码之数据的代理访问
2018/12/11 Javascript
node.js 基于cheerio的爬虫工具的实现(需要登录权限的爬虫工具)
2019/04/10 Javascript
使用typescript构建Vue应用的实现
2019/08/26 Javascript
NUXT SSR初级入门笔记(小结)
2019/12/16 Javascript
vue实现购物车加减
2020/05/30 Javascript
Python实现的redis分布式锁功能示例
2018/05/29 Python
pip命令无法使用的解决方法
2018/06/12 Python
python爬虫的数据库连接问题【推荐】
2018/06/25 Python
Keras使用tensorboard显示训练过程的实例
2020/02/15 Python
pytorch VGG11识别cifar10数据集(训练+预测单张输入图片操作)
2020/06/24 Python
css3一款3D字体带阴影效果的实现步骤
2013/03/20 HTML / CSS
如何启动时不需输入用户名与密码
2014/05/09 面试题
医院护士的求职信
2014/01/03 职场文书
社区优秀志愿者材料
2014/02/02 职场文书
人力资源经理的岗位职责范本
2014/02/28 职场文书
公司总经理岗位职责
2014/03/15 职场文书
倡议书格式模板
2014/05/13 职场文书
幼儿园户外活动总结
2014/07/04 职场文书
天猫活动策划方案
2014/08/21 职场文书
个人三严三实对照检查材料
2014/09/25 职场文书
离职证明范本
2015/06/12 职场文书
宾馆安全管理制度
2015/08/06 职场文书
团队执行力培训心得体会
2015/08/15 职场文书
导游词之云南丽江古城
2019/09/17 职场文书