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基于数组函数实现关联表的编辑操作。分享给大家供大家参考,具体如下: 需求为,在创建学校时,需要添加应用,于是创建了个学校应用关联表,编辑学校并提交时,后台需要判断更新...

php输出指定时间以前时间格式的方法

本文实例讲述了php输出指定时间以前时间格式的方法。分享给大家供大家参考。具体分析如下: 比如说你需要在php中输出3天前,20分钟以前,可以参考下面的代码 function ago...

php单元测试phpunit入门实例教程

本文实例讲述了php单元测试phpunit。分享给大家供大家参考,具体如下: 这篇文章提供了一些phpunit官方教程没有提到的信息,帮助初学者快速了解php单元测试,在phpunit官...

PHP实现简单汉字验证码

现在越来越多的网站都开始使用汉字验证码了,既增加了我们国人的亲切感,同时也增加了机器破解的难度,这里我就简单粗暴的说一下。。。 创建背景画布 $image = imagecreate...

PHP 采集程序 常用函数

当前的脚本网址 function get_php_url(){ if(!empty($_SERVER["REQUEST_URI"])){ $scriptName = $_SERVER["...