php修改上传图片尺寸的方法

yipeiwu_com5年前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计划任务之关闭浏览器后仍然继续执行的函数

备忘一下这个函数: 函数名称:ignore_user_abort 本函数配置或取得使用端连接中断后,PHP 程序是否仍继续执行。默认值为中断连接后就停止执行。在 PHP 配置文件中 (p...

浅析PHP的静态成员函数效率更高的原因

很多php开发人员都知道, 使用类的静态成员函数效率比类的普通成员函数的要高,本文从应用层次分析这个问题 下面是一个范例: 复制代码 代码如下:<?php // php静态方法测试...

PHP实现的获取文件mimes类型工具类示例

本文实例讲述了PHP实现的获取文件mimes类型工具类。分享给大家供大家参考,具体如下: <?php /* * Copyright 2010-2013 Amazon....

FCKeditor的安装(PHP)

1.下载新最版的FCKEditor,解压 2.删除/FCKeditor/目录下除fckconfig.js, fckeditor.js, fckstyles.xml,&...

PHP读取XML格式文件的方法总结

本文实例总结了PHP读取XML格式文件的方法。分享给大家供大家参考,具体如下: books.xml文件: <books> <book> <author&...