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面向对象程序设计方法。分享给大家供大家参考,具体如下: PHP5开始支持面向对象,示例如下: <?php class classna...

php Sql Server连接失败问题及解决办法

1、确认数据库服务开启状态 2、php.ini配置中的扩展打开 3、检查数据库相关的版本 (1)Sql2000此时要检查php目录和apache的bin目录下的ntwdblib.dll文...

PHP中header用法小结

本文实例总结了PHP中header用法。分享给大家供大家参考,具体如下: PHP 中 header()函数的作用是给客户端发送头信息。 什么是头信息? 这里只作简单解释,详细的自己看ht...

PHP 将dataurl转成图片image方法总结

PHP 将dataurl转成图片image方法 使用canvas 生成的图片,是使用dataurl的,php无法直接通过file_put_contents方法保存到本地电脑,需要做一下转...

php对二维数组进行相关操作(排序、转换、去空白等)

技巧提示: array_keys($array) //返回所有键名 array_values($array) //返回所有键值 $result=array_rever...