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使用pack处理二进制文件的方法

php读写二进制文件可以使用pack和unpack函数。 今天要处理一个二进制文件的问题,所以需要用一下,特意了解一下pack的用法,unpack用法与此类似。 简单来说,pack函数就...

php通过两层过滤获取留言内容的方法

本文实例讲述了php通过两层过滤获取留言内容的方法。分享给大家供大家参考,具体如下: //两层过滤,获取留言的内容 $str='<div id="read_111111" st...

PHP简单数据库操作类实例【支持增删改查及链式操作】

本文实例讲述了PHP简单数据库操作类。分享给大家供大家参考,具体如下: 在进行项目开发时,数据库是必不可少的东西了。但是很多时候却又对数据库SQL语句的繁杂而感到头疼。提供一个我自己使用...

PHP输出时间差函数代码

PHP输出时间差函数 复制代码 代码如下:<?php  date_default_timezone_set('PRC'); //默认时区  echo "今天:"...

php json中文编码为null的解决办法

今天使用json_encode函数,发现中文竟成了null。 原因分析:使用json_encode函数应应使用utf-8编码,我的页面用的是gbk. 解决:在json_encode函数前...