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实现图片上传时添加文字和图片水印技巧

本文实现的功能特别适用于一些商城和图片站中,分享了图片在上传时添加文字和图片水印的技巧,供大家参考,具体内容如下 1. water.class.php <?php h...

php字符串函数学习之strstr()

复制代码 代码如下: <?php /* 定义和用法 strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。 该函数返回字符串的其余部分(从匹配点)。如果未找到所...

PHP大文件切割上传功能实例分析

PHP大文件切割上传功能实例分析

本文实例讲述了PHP大文件切割上传功能。分享给大家供大家参考,具体如下: 大家都知道php上传文件有限制,如果没有修改过php.ini文件的话,默认的上传大小限制为2M,那么该如何上传大...

PHP,ASP.JAVA,JAVA代码格式化工具整理

PHP代码格式化工具http://www.waterproof.fr/products/phpCodeBeautifier/最近修改一个代码,里面完全没有缩进,用这个能够格式化一下。相当...

php使用ereg验证文件上传的方法

本文实例讲述了php使用ereg验证文件上传的方法。分享给大家供大家参考。具体分析如下: ereg格式如下: 复制代码 代码如下:ereg(正规表达式,字符串,[匹配部分数组名]); 这...