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

yipeiwu_com5年前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函数preg_match_all正则表达式的基本使用详细解析

了解正则表达式之前,须要掌握一些常用的正则表达式的基础知识,这些如果能记得最好记得,记不住须要用的时候能查到就行,就多个特殊字符,所以说正则表达式玩的就是特殊,具体大家可以查看更加细致的...

PHP中SimpleXML函数用法分析

本文实例讲述了关于php中SimpleXML 函数的用法,此函数是允许您把 XML 转换为对象,分享给大家供大家参考。具体分析如下: SimpleXML 函数允许您把 XML 转换为对象...

PHP-FPM实现性能优化

简介: PHP-FPM 是一个 PHP FastCGI 管理器,一般 Nginx 上面跑 PHP 程序都会将 PHP 程序丢给 PHP-FPM 来解析。好了,就这样! PHP 5.4 开...

抓取YAHOO股票报价的类

复制代码 代码如下:<? function getYahooQuote($stockSymbol = "CCR") { if (!$targetURL) $targetURL =...

php中\r \r\n \t的区别示例介绍

\n 软回车: 在Windows 中表示换行且回到下一行的最开始位置。相当于Mac OS 里的 \r 的效果。 在Linux、unix 中只表示换行,但不会回到下一行的开始位置。 \r...