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取进制余数函数代码

复制代码 代码如下: //取进制位上的数值 function getRemainder($num, $bin, $pos, &$result = 0){ //author lianq.n...

php中time()与$_SERVER[REQUEST_TIME]用法区别

php中time()与$_SERVER[REQUEST_TIME]用法区别

本文实例详细讲述了php中time()与$_SERVER[REQUEST_TIME]用法的区别。分享给大家供大家参考。具体分析如下: 简单的说time()与$_SERVER["REQUE...

php模拟socket一次连接,多次发送数据的实现代码

复制代码 代码如下: <?php //post.php function Post($host,$port) { //$host="127.0.0.1"; //建立连接 $conn...

php后台程序与Javascript的两种交互方式

方法一:通过Cookie交互。 一共是三个文件,分别为:index.htm,action.php,main.htm 原理为前台页面main.htm和后台action.php通过页面框架...

PHP 递归效率分析

而且是差了3倍的效率。所以,PHP中的递归一定要小心的对待。 最近写了一个快速排序的算法,发现PHP中的递归效率不能一刀切,在各种不同的服务器中,可能会表现不一样。 复制代码 代码如下:...