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将Excel导入数据库及数据库数据导出至Excel的方法

本文实例讲述了PHP将Excel导入数据库及数据库数据导出至Excel的方法。分享给大家供大家参考。具体实现方法如下: 一.导入 导入需要使用能读取Excel的组件,网上也有比较好的组件...

PHP 金额数字转换成英文

复制代码 代码如下:<?php $num=1220.01; echo fmoney($num);//结果:1,220.21 echo umoney($num); //结果:ONE...

PHP 存储文本换行实现方法

\n LF或ASCII中的0x0A(10) \r CR或ASCII中的0x0D(13) \t 水平制表符-HT或ASCII中的0x09(9) \\ 反斜杠 \$ 美圆符 \" 双引号 \...

PHP 安全检测代码片段(分享)

复制代码 代码如下:/**  * html转换输出(只转义' " 保留Html正常运行)  * @param $param  * @return strin...

木翼下载系统中说明的PHP安全配置方法

一、Web服务器安全 PHP其实不过是Web服务器的一个模块功能,所以首先要保证Web服务器的安全。当然Web服务器要安全又必须是先保证系统安全,这样就扯远了,无穷无尽。PHP可以和...