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使用token防止表单重复提交的方法

本文实例讲述了PHP使用token防止表单重复提交的方法。分享给大家供大家参考,具体如下: <?php /* * PHP使用token防止表单重复提交 * 此处理方法纯...

PHP实现会员账号单唯一登录的方法分析

本文实例讲述了PHP实现会员账号单唯一登录的方法。分享给大家供大家参考,具体如下: 情景再现 同一会员账号限制在同一台设备(电脑、手机、Ipad等)上单点登录,重复登录后,原登录访问页面...

PHP数据流应用的一个简单实例

PHP数据流应用的一个简单实例

复制代码 代码如下: <?php $count = 5; start: if($count < 5) echo "You can try {$count} time, ";...

php生成短域名函数

php生成短域名函数 public function createRandCode($string) { $code = ''; $hex_code = '1qaz2...

php根据指定位置和长度获得子字符串的方法

本文实例讲述了php根据指定位置和长度获得子字符串的方法。分享给大家供大家参考。具体分析如下: php的substr函数功能非常强大,不断可以从前往后去子字符串还可以从后往前取字符串...