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实现指定字符串中查找子字符串的方法

本文实例讲述了php实现指定字符串中查找子字符串的方法。分享给大家供大家参考。具体分析如下: 对strpos()函数可以用来在php中查找子字符串。strpos()函数将试图找到子字符串...

PHP 字符串长度判断效率更高的方法

有经验的程序员发现,php判断字符串长度,使用isset()在速度上比strlen()更快,执行效率更高。即:复制代码 代码如下:$str = ‘aaaaaa';if(strlen($s...

PHP实现对xml的增删改查操作案例分析

本文实例讲述了PHP实现对xml的增删改查操作。分享给大家供大家参考,具体如下: 案例: index.php <?php header("content-type:te...

php输入数据统一类实例

本文实例讲述了php输入数据统一类。分享给大家供大家参考。具体如下: <?php class cls_request{ private $getdata;//存储ge...

php实现文件上传及头像预览功能

php实现文件上传及头像预览功能

php文件上传原理是通过form表单的enctype="multipart/form-data"属性将文件临时放到wamp文件夹中的tmp目录下,再通过后台php程序将文件保存在体统中。...