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实现的分解质因数操作。分享给大家供大家参考,具体如下: 思路: 如果要计算$num的质数,则至少收集$num以内的质数数组,判断$num是否在质数数组里: 如果否,则...

php随机获取金山词霸每日一句的方法

本文实例讲述了php随机获取金山词霸每日一句的方法。分享给大家供大家参考。具体实现方法如下: header('Content-Type:text/html; charset=utf-...

PHP取整函数:ceil,floor,round,intval的区别详细解析

我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval。 ceil -- 进一法取整说明float ceil ( float value ) 返回不小于 v...

phpmyadmin打开很慢的解决方法

phpmyadmin4系列通通加载缓慢的最终原因是最近phpmyadmin的官网经常打不开,而phpmyadmin页面会自动检查官网上的程序版本更新,所以当你进入phpmyadmin管理...

PHP字符串 ==比较运算符的副作用

复制代码 代码如下: $a = '212345678912000005'; $b = '212345678912000001'; var_dump($a == $b); 这段代码的输出...