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二维数组去重的方法。分享给大家供大家参考,具体如下: 都知道一维数组去重用系统函数 array_unique($arr) 然后今天我用到二维数组了,也想去重,百度一大...

PHP实现的迪科斯彻(Dijkstra)最短路径算法实例

PHP实现的迪科斯彻(Dijkstra)最短路径算法实例

本文实例讲述了PHP实现的迪科斯彻(Dijkstra)最短路径算法。分享给大家供大家参考,具体如下: 一、待解决问题 单源最短路径问题,在给定有向图中求一个顶点(单源顶点)到其他所有顶点...

PHP对表单提交特殊字符的过滤和处理方法汇总

PHP关于表单提交特殊字符的处理方法做个汇总,主要涉及htmlspecialchars/addslashes/stripslashes/strip_tags/mysql_real_esc...

PHP实现根据浏览器跳转不同语言页面代码

复制代码 代码如下:<?php$lan = $_SERVER['HTTP_ACCEPT_LANGUAGE'];   //获取浏览器语言版本if (preg_ma...

windows下安装php的memcache模块的方法

windows下安装php的memcache模块的方法

要求必备知识 熟悉基本编程环境搭建。 运行环境 windows 7(64位); php-5.3; memcached-1.2.6 下载地址 环境下载 什么是PHP Memcache模块...