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程序设计有所帮助。

相关文章

Discuz Uchome ajaxpost小技巧

比如默认submit按钮这样操作:onclick="ajaxpost('formid')";之类的,我们可以先这样。。 onclick="$('__formid').innerText=...

PHP答题类应用接口实例

本文实例讲述了PHP答题类应用接口的实现方法。分享给大家供大家参考。具体实现方法如下: question_get.php文件如下: 复制代码 代码如下:<?php ...

php自定义hash函数实例

本文实例讲述了php自定义hash函数实现方法。分享给大家供大家参考。具体分析如下: 这里演示php实现的一个简单hash算法,可以用来加密,不过这个函数过于简单,不能用来解密 fu...

php 冒泡排序 交换排序法

复制代码 代码如下: $a=array('11','2','13','4','22'); $num = count($a); for($i=0;$i<$num;$i++){ for...

php中0,null,empty,空,false,字符串关系的详细介绍

在一个项目中遇到了一个奇怪的问题,耗费了我不少时间都没有解决,最终调试发现是判断的问题—-关于0和 ‘ ‘ (空单引号,为好看清我加了个空格)的判断,我发现 0==” 居然成立,郁闷的同...