php修改上传图片尺寸的方法

5年以前  |  阅读数:470 次  |  编程语言: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分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例