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 应用程序的安全 -- 不能违反的四条安全规则

大家都知道安全性是重要的,但是行业中的趋势是直到最后一刻才添加安全性。既然不可能完全保护 Web 应用程序,那么为什么要费这个劲儿呢,不是吗?不对。只需采用一些简单的...

PHP操作Redis常用技巧总结

本文实例讲述了PHP操作Redis常用技巧。分享给大家供大家参考,具体如下: 一、Redis连接与认证 //连接参数:ip、端口、连接超时时间,连接成功返回true,否则返回fals...

PHP使用array_merge重新排列数组下标的方法

本文实例讲述了PHP使用array_merge重新排列数组下标的方法。分享给大家供大家参考。具体如下: 用了一个array_unique去除了一个数组里面的重复,但是发现下标保留了原数组...

PHP怎么实现网站保存快捷方式方便用户随时浏览

PHP怎么实现网站保存快捷方式呢?下面是一段PHP代码,下面这段代码,可以PHP实现网站保存快捷方式,以便用户随时浏览。 复制代码 代码如下: <?php $Shortcut =...

PHP strripos函数用法总结

php strripos()函数 语法 作用:寻找某字符串中某字符最后出现的位置,不区分大小写 语法: strripos(string,find,start) 参数: string...