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 Redis内存占用

降低PHP Redis内存占用

1、降低redis内存占用的优点  1、有助于减少创建快照和加载快照所用的时间  2、提升载入AOF文件和重写AOF文件时的效率  3、缩短从服务器进行同步所需的时间  4、无需添加额外...

php split汉字

第一种办法: 加载 Encode模块,前提是你需要安装这个模块 例子代码: 复制代码 代码如下: $str=decode("gb2312",$names[$index]); @chars...

DISCUZ 论坛管理员密码忘记的解决方法

DISCUZ论坛管理员密码忘记了怎么办? 今天,一个朋友在QQ上问我,“如果DISCUZ论坛管理员密码忘记了 从MYSQL 哪里找啊?”, 他用的是HostMonster的虚拟主机。 y...

php使用unset()删除数组中某个单元(键)的方法

本文实例讲述了php使用unset()删除数组中某个单元(键)的方法。分享给大家供大家参考。具体分析如下: unset既可以删除变量,也可以删除数组中某个单元。但要注意的是,数组不会重建...

PHP实现简单的新闻发布系统实例

本文实例讲述了PHP实现简单的新闻发布系统。分享给大家供大家参考。具体如下: 本人小白,一直在公司用模板和框架写PHP,发现有时候连基本的sql语句都忘记了,所以有空想把PHP基础复习下...