php修改上传图片尺寸的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了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实现最简单的MVC框架实例教程

本文以一个实例的形式讲述了PHP实现MVC框架的过程,比较浅显易懂。现分享给大家供大家参考之用。具体分析如下: 首先,在学习一个框架之前,基本上我们都需要知道什么是mvc,即model-...

PHP IDE PHPStorm配置支持友好Laravel代码提示方法

PHP IDE PHPStorm配置支持友好Laravel代码提示方法

PHPStorm神器可以支持更友好的laravel框架代码提示(点击查看),只需要执行如下才做: 第一步:在项目的composer.json中添加如下一行 复制代码 代码如下: "req...

PHP中异常处理的一些方法整理

每一个新的功能添加到PHP运行时会创建一个指数随机数,通过这样的方式开发者可以使用和甚至滥用这个新特性。然而,直到一些好的和坏的使用情况陆续出现开发者们才达成了共识。当这些新案例不断浮现...

php使用Cookie控制访问授权的方法

本文实例讲述了php使用Cookie控制访问授权的方法。分享给大家供大家参考。具体如下: 复制代码 代码如下:<?php     ...

PHP实现的Redis操作通用类示例

本文实例讲述了PHP实现的Redis操作通用类。分享给大家供大家参考,具体如下: 找到一个比较全的Redis PHP操作类库,分享给大家 <?php /** * re...