PHP好的特性别放过-匿名方法'
时间:2007-11-24
来源:互联网
复制PHP内容到剪贴板
* @desc Resize image
* @auther BianYuan
* @param String $imageFrom
* @param Integer $maxwidth
* @param Integer $maxheight
* @distDir String $distDir
* @return Boolean
*/
function imageResize($source, $maxwidth=90, $maxheight=110, $distDir=""){
$imgName = basename($source);
$output = ""; 匿名方法
//if some user upload very large imagest.....
@ list($width, $height, $type) = getimagesize($source);
switch ($type)
{
case 1:
$imageFrom = imagecreatefromgif($source);
$output = "imagegif";
break;
case 2:
$imageFrom = imagecreatefromjpeg($source);
$output = "imagejpeg";
break;
case 3:
$imageFrom = imagecreatefrompng($source);
$output = "imagepng";
break;
default:
return false;
}
if(! $img = @ imagecreatetruecolor($maxwidth, $maxheight)){
return false;
}
if(($width > $maxwidth) || ($height > $maxheight)){
imagecopyresampled($img, $imageFrom, 0, 0, 0, 0, $maxwidth, $maxheight, $width, $height);
$output ($img, $distDir ."/". $imgName);
ImageDestroy ($img);
}else{
if(! @ copy($source, $distDir ."/". $imgName)){
return false;
}
}
return true;
}
ini_set('memory_limit', '-1');全局设置中这个别忘了设置
PHP代码:
/*** @desc Resize image
* @auther BianYuan
* @param String $imageFrom
* @param Integer $maxwidth
* @param Integer $maxheight
* @distDir String $distDir
* @return Boolean
*/
function imageResize($source, $maxwidth=90, $maxheight=110, $distDir=""){
$imgName = basename($source);
$output = ""; 匿名方法
//if some user upload very large imagest.....
@ list($width, $height, $type) = getimagesize($source);
switch ($type)
{
case 1:
$imageFrom = imagecreatefromgif($source);
$output = "imagegif";
break;
case 2:
$imageFrom = imagecreatefromjpeg($source);
$output = "imagejpeg";
break;
case 3:
$imageFrom = imagecreatefrompng($source);
$output = "imagepng";
break;
default:
return false;
}
if(! $img = @ imagecreatetruecolor($maxwidth, $maxheight)){
return false;
}
if(($width > $maxwidth) || ($height > $maxheight)){
imagecopyresampled($img, $imageFrom, 0, 0, 0, 0, $maxwidth, $maxheight, $width, $height);
$output ($img, $distDir ."/". $imgName);
ImageDestroy ($img);
}else{
if(! @ copy($source, $distDir ."/". $imgName)){
return false;
}
}
return true;
}
复制PHP内容到剪贴板
<?php
/**
* @company xingquan
* @auther BianYuan
* @date Wed Nov 07 16:24:35 CST 2007
* @copyright xingQuan
* @file common.inc.php
* @version 0.1
*/
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('UPLOAD', ROOT . DS . "upload");
// Security option
define('IN_SITE', true);
// Display no errors
error_reporting(E_ALL ^ E_NOTICE);
// Sets the time zone for the DateTime object
ini_set('date.timezone','Asia/Shanghai');
// Auto load php file path, like windows $PATH
ini_set('include_path', ini_get('include_path')
. PATH_SEPARATOR . ROOT . DS . 'librarys/Pear/');
ini_set('memory_limit', '-1');
// Load core file
require_once("DB.php");
require_once("Pager/Pager.php");
require_once(ROOT . DS . "librarys/config.inc.php");
require_once(ROOT . DS . "librarys/function.inc.php");
require_once(ROOT . DS . "librarys/Class/tpl.class.php");
$tpl = new Tpl();
$options = getOption();
$tpl->assign('options', $options);
header('Content-Type: text/html; charset=utf-8');
?>
[ 本帖最后由 liuxingyuyuni 于 2007-11-24 14:01 编辑 ] PHP代码:
<?php
/**
* @company xingquan
* @auther BianYuan
* @date Wed Nov 07 16:24:35 CST 2007
* @copyright xingQuan
* @file common.inc.php
* @version 0.1
*/
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('UPLOAD', ROOT . DS . "upload");
// Security option
define('IN_SITE', true);
// Display no errors
error_reporting(E_ALL ^ E_NOTICE);
// Sets the time zone for the DateTime object
ini_set('date.timezone','Asia/Shanghai');
// Auto load php file path, like windows $PATH
ini_set('include_path', ini_get('include_path')
. PATH_SEPARATOR . ROOT . DS . 'librarys/Pear/');
ini_set('memory_limit', '-1');
// Load core file
require_once("DB.php");
require_once("Pager/Pager.php");
require_once(ROOT . DS . "librarys/config.inc.php");
require_once(ROOT . DS . "librarys/function.inc.php");
require_once(ROOT . DS . "librarys/Class/tpl.class.php");
$tpl = new Tpl();
$options = getOption();
$tpl->assign('options', $options);
header('Content-Type: text/html; charset=utf-8');
?>
作者: liuxingyuyuni 发布时间: 2007-11-24

作者: luzhou 发布时间: 2007-11-24
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28