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 fopen函数用法实例讲解

php fopen()函数用于打开文件或者 URL。 php fopen()函数 语法 作用:打开文件或者 URL。 语法: fopen(filename,mode,include_...

PHP批量修改文件名称的方法分析

本文实例讲述了PHP批量修改文件名称的方法。分享给大家供大家参考,具体如下: 在这里我们利用一个战地自己写的一个例子来具体分析一下利用PHP批量修改文件名称的思路和注意事项。 从这个例子...

对比分析php中Cookie与Session的异同

让大家对Cookie和Session有一个更深入的了解,并对自己的开发工作中灵活运用带来启示。 一、cookie机制 Cookies是服务器在本地机器上存储的小段文本并随每一个请求发送至...

jq的get传参数在utf-8中乱码问题的解决php版

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E...

PHP数组式访问接口ArrayAccess用法分析

本文实例讲述了PHP数组式访问接口ArrayAccess用法。分享给大家供大家参考,具体如下: PHP  ArrayAccess接口又叫数组式访问接口,该接口的作用是提供像访问...