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将会员数据导入到ucenter的代码

我们要用的会员表结构 复制代码 代码如下: create table if not exists `net_111cnnet` ( `id` int(11) not null auto_...

php 常用类汇总 推荐收藏

图表库下面的类库可以让你很简单就能创建复杂的图表和图片。当然,它们需要GD库的支持。pChart - 一个可以创建统计图的库。Libchart - 这也是一个简单的统计图库。JpGrap...

快速配置PHPMyAdmin方法

    那么我们现在开始进行安装配置:     1.一般网上下载到的PHPMyAdmin是一个压缩包,我们...

PHP获取网页所有连接的方法(附demo源码下载)

本文实例讲述了PHP获取网页所有连接的方法。分享给大家供大家参考,具体如下: function getHtml($url, $charset='utf-8') { $curl =...

PHP用continue跳过本次循环中剩余代码的注意点

前言 大家都知道,在PHP中continue 在循环结构用用来跳过本次循环中剩余的代码并在条件求值为真时开始执行下一次循环。一定要注意的是,用了continue要用“;”来隔开其他的代码...