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字符串常见操作。分享给大家供大家参考,具体如下: 字符串的定义 可以用单引号或双引号来定义字符串 <?php $str = "hello"; $st...

php通过递归方式复制目录和子目录的方法

本文实例讲述了php通过递归方式复制目录和子目录的方法。分享给大家供大家参考。具体实现方法如下: <?php function recurse_copy($src,$...

php自定义apk安装包实例

本文实例讲述了php自定义apk安装包的方法,分享给大家供大家参考。具体实现方法如下: 众所周知,apk格式安装文件是android智能系统的安装文件,下面我们来看一个利用php实现自定...

PHP中使用glob函数实现一句话删除某个目录下的所有文件

收集自网上: 复制代码 代码如下: array_map('unlink',glob('*')); 抛砖引玉而已,有很多朋友可能还不知道有glob这个函数吧。更多的用法看手册吧。 PHP...

将word转化为swf 如同百度文库般阅读实现思路及代码

将word转化为swf 如同百度文库般阅读实现思路及代码

复制代码 代码如下: <SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">实现如同百度文库那样类似功能需要进行一系...