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来实现一个进度条功能,谷歌了一下,找了个合适的代码。下面直接上代码: <&...

Yii2中简单的场景使用介绍

本文主要介绍的是关于Yii2简单场景使用的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍: 直接上代码(主要部分): 模型层: public function rule...

浅析php过滤html字符串,防止SQL注入的方法

批量过滤post,get敏感数据复制代码 代码如下:$_GET = stripslashes_array($_GET);$_POST = stripslashes_array($_POS...

PHP获得当日零点时间戳的方法分析

本文实例讲述了PHP获得当日零点时间戳的方法。分享给大家供大家参考,具体如下: 今天项目中,想每天看到的是当天的全部信息,所以想获得当天零点的时间戳,复习下时间戳的相关知识,总结如下:...

PHP中类型转换 ,常量,系统常量,魔术常量的详解

PHP中类型转换 ,常量,系统常量,魔术常量的详解 1.自动类型转换; 在运算和判断时,会进行自动类型转换; 1)其他类型转为bool,判断时转换; 1)整型转布尔型:0转fal...