wordpress里面的慢SQL,把wp_postmeta.meta_key的类型由varchar(255)改变为varchar(191)

SELECT DISTINCT meta_key
			FROM wp_postmeta
			WHERE meta_key NOT BETWEEN '_' AND '_z'
			HAVING meta_key NOT LIKE '\\_%'
			ORDER BY meta_key
			LIMIT 30;

当wordpress里面的慢SQL,把wp_postmeta.meta_key的类型由varchar(255)改变为varchar(191)
目前我的mysql版本是5.5
不知道新版本有没有改进,看了别人描述(https://core.trac.wordpress.org/ticket/33885#comment:5),说是只取前191个字节做索引。

discuz的php防止sql注入函数

转载自:http://www.jb51.net/article/26069.htm
最早开始学习php的时候根本没考虑过安全方面的问题,那时候就是想能做出功能就是万岁了。随着做项目的时间慢慢加长,越来越感觉到网站安全方面的问题十分重要。
最近在做一个主题投票网站,客户懂一些程序方面的东西。有特别要求需要过滤一些字符防止sql注入。本来这方面就没有特别的研究过。呵呵,又发扬了一回拿来主义。把discuz论坛的sql防注入函数取了来!

$magic_quotes_gpc = get_magic_quotes_gpc(); 
@extract(daddslashes($_COOKIE)); 
@extract(daddslashes($_POST)); 
@extract(daddslashes($_GET)); 
if(!$magic_quotes_gpc) { 
$_FILES = daddslashes($_FILES); 
} 
 
 
function daddslashes($string, $force = 0) { 
if(!$GLOBALS['magic_quotes_gpc'] || $force) { 
if(is_array($string)) { 
foreach($string as $key => $val) { 
$string[$key] = daddslashes($val, $force); 
} 
} else { 
$string = addslashes($string); 
} 
} 
return $string; 
}

大家可以增强下面的代码加以保护服务器的安全,PHP防止SQL注入安全函数十分重要!

/* 
函数名称:inject_check() 
函数作用:检测提交的值是不是含有SQL注射的字符,防止注射,保护服务器安全 
参  数:$sql_str: 提交的变量 
返 回 值:返回检测结果,ture or false 
*/ 
function inject_check($sql_str) { 
return eregi('select|insert|and|or|update|delete|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile', $sql_str); // 进行过滤 
} 
 
/* 
函数名称:verify_id() 
函数作用:校验提交的ID类值是否合法 
参  数:$id: 提交的ID值 
返 回 值:返回处理后的ID 
*/ 
function verify_id($id=null) { 
if (!$id) { exit('没有提交参数!'); } // 是否为空判断 
elseif (inject_check($id)) { exit('提交的参数非法!'); } // 注射判断 
elseif (!is_numeric($id)) { exit('提交的参数非法!'); } // 数字判断 
$id = intval($id); // 整型化 
 
return $id; 
} 
 
/* 
函数名称:str_check() 
函数作用:对提交的字符串进行过滤 
参  数:$var: 要处理的字符串 
返 回 值:返回过滤后的字符串 
*/ 
function str_check( $str ) { 
if (!get_magic_quotes_gpc()) { // 判断magic_quotes_gpc是否打开 
$str = addslashes($str); // 进行过滤 
} 
$str = str_replace("_", "\_", $str); // 把 '_'过滤掉 
$str = str_replace("%", "\%", $str); // 把 '%'过滤掉 
 
return $str; 
} 
 
/* 
函数名称:post_check() 
函数作用:对提交的编辑内容进行处理 
参  数:$post: 要提交的内容 
返 回 值:$post: 返回过滤后的内容 
*/ 
function post_check($post) { 
if (!get_magic_quotes_gpc()) { // 判断magic_quotes_gpc是否为打开 
$post = addslashes($post); // 进行magic_quotes_gpc没有打开的情况对提交数据的过滤 
} 
$post = str_replace("_", "\_", $post); // 把 '_'过滤掉 
$post = str_replace("%", "\%", $post); // 把 '%'过滤掉 
$post = nl2br($post); // 回车转换 
$post = htmlspecialchars($post); // html标记转换 
 
return $post; 
}

php获取用户IP地址

具体请下载

<?php
require_once './Getip/qqwry.class.php';
$ip 		=	get_user_ip();
//$ip 		=	'58.61.214.48';
$QQWry		=	new QQWry;
$ifErr		=	$QQWry->QQWry($ip); 
$location	=	$QQWry->Country.$QQWry->Local;
if(!empty($location))
{
	$location =	iconv('GB2312', 'UTF-8', $location);
}
else
{
	$location = '未知地区';
}
 
 
/*
	 * 获取用户的Ip地址
	 */
	function get_user_ip()
    {
		/*
	        if($_SERVER["HTTP_X_REAL_IP"])
			{
				$ip	=	$_SERVER["HTTP_X_REAL_IP"];
			}
			else
		*/
		if($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
        {                                             
               $ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
        }                                             
        elseif($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])   
        {                                             
               $ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
        }                                             
        elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])      
        {                                             
               $ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];  
        }                                             
        elseif (getenv("HTTP_X_FORWARDED_FOR"))          
        {                                             
               $ip = getenv("HTTP_X_FORWARDED_FOR");  
        }                                             
        elseif (getenv("HTTP_CLIENT_IP"))                
        {                                             
               $ip = getenv("HTTP_CLIENT_IP");  
        }         
        elseif (getenv("REMOTE_ADDR"))  {                                             
               $ip = getenv("REMOTE_ADDR");
        }      
        else    {                                             
               $ip = "Unknown";   
        } 
 
        return $ip;
    }
?>
<div style='font-size:18px;font-weight: 500;font-family: "microsoft yahei";margin-top:10px;'>
                    我的IP地址:<?php echo $ip; ?><br /><br />
                    所属地区:&nbsp;&nbsp;<?php echo $location; ?>
</div>

PHP 汉字转拼音URL

想要一个汉字转拼音URL的功能,于是在这里找到了http://hahaxiao.techweb.com.cn/archives/750.html,但是它只是把汉字转换为拼音,不能生成wo-ai-ni这样的URL格式,所以我小小的改动了一下。
源代码来自:http://hahaxiao.techweb.com.cn/archives/750.html

<?php
/**
*
* 中文转换为拼音
*
*/
function cn2pinyin($_String, $_Code='gb2312') 
{
	$_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei|ben|beng|bi|bian|biao|bie|bin|bing|bo|bu|ca|cai|can|cang|cao|ce|ceng|cha" .
	"|chai|chan|chang|chao|che|chen|cheng|chi|chong|chou|chu|chuai|chuan|chuang|chui|chun|chuo|ci|cong|cou|cu|" .
	"cuan|cui|cun|cuo|da|dai|dan|dang|dao|de|deng|di|dian|diao|die|ding|diu|dong|dou|du|duan|dui|dun|duo|e|en|er" .
	"|fa|fan|fang|fei|fen|feng|fo|fou|fu|ga|gai|gan|gang|gao|ge|gei|gen|geng|gong|gou|gu|gua|guai|guan|guang|gui" .
	"|gun|guo|ha|hai|han|hang|hao|he|hei|hen|heng|hong|hou|hu|hua|huai|huan|huang|hui|hun|huo|ji|jia|jian|jiang" .
	"|jiao|jie|jin|jing|jiong|jiu|ju|juan|jue|jun|ka|kai|kan|kang|kao|ke|ken|keng|kong|kou|ku|kua|kuai|kuan|kuang" .
	"|kui|kun|kuo|la|lai|lan|lang|lao|le|lei|leng|li|lia|lian|liang|liao|lie|lin|ling|liu|long|lou|lu|lv|luan|lue" .
	"|lun|luo|ma|mai|man|mang|mao|me|mei|men|meng|mi|mian|miao|mie|min|ming|miu|mo|mou|mu|na|nai|nan|nang|nao|ne" .
	"|nei|nen|neng|ni|nian|niang|niao|nie|nin|ning|niu|nong|nu|nv|nuan|nue|nuo|o|ou|pa|pai|pan|pang|pao|pei|pen" .
	"|peng|pi|pian|piao|pie|pin|ping|po|pu|qi|qia|qian|qiang|qiao|qie|qin|qing|qiong|qiu|qu|quan|que|qun|ran|rang" .
	"|rao|re|ren|reng|ri|rong|rou|ru|ruan|rui|run|ruo|sa|sai|san|sang|sao|se|sen|seng|sha|shai|shan|shang|shao|" .
	"she|shen|sheng|shi|shou|shu|shua|shuai|shuan|shuang|shui|shun|shuo|si|song|sou|su|suan|sui|sun|suo|ta|tai|" .
	"tan|tang|tao|te|teng|ti|tian|tiao|tie|ting|tong|tou|tu|tuan|tui|tun|tuo|wa|wai|wan|wang|wei|wen|weng|wo|wu" .
	"|xi|xia|xian|xiang|xiao|xie|xin|xing|xiong|xiu|xu|xuan|xue|xun|ya|yan|yang|yao|ye|yi|yin|ying|yo|yong|you" .
	"|yu|yuan|yue|yun|za|zai|zan|zang|zao|ze|zei|zen|zeng|zha|zhai|zhan|zhang|zhao|zhe|zhen|zheng|zhi|zhong|" .
	"zhou|zhu|zhua|zhuai|zhuan|zhuang|zhui|zhun|zhuo|zi|zong|zou|zu|zuan|zui|zun|zuo";
	$_DataValue = "-20319|-20317|-20304|-20295|-20292|-20283|-20265|-20257|-20242|-20230|-20051|-20036|-20032|-20026|-20002|-19990" .
	"|-19986|-19982|-19976|-19805|-19784|-19775|-19774|-19763|-19756|-19751|-19746|-19741|-19739|-19728|-19725" .
	"|-19715|-19540|-19531|-19525|-19515|-19500|-19484|-19479|-19467|-19289|-19288|-19281|-19275|-19270|-19263" .
	"|-19261|-19249|-19243|-19242|-19238|-19235|-19227|-19224|-19218|-19212|-19038|-19023|-19018|-19006|-19003" .
	"|-18996|-18977|-18961|-18952|-18783|-18774|-18773|-18763|-18756|-18741|-18735|-18731|-18722|-18710|-18697" .
	"|-18696|-18526|-18518|-18501|-18490|-18478|-18463|-18448|-18447|-18446|-18239|-18237|-18231|-18220|-18211" .
	"|-18201|-18184|-18183|-18181|-18012|-17997|-17988|-17970|-17964|-17961|-17950|-17947|-17931|-17928|-17922" .
	"|-17759|-17752|-17733|-17730|-17721|-17703|-17701|-17697|-17692|-17683|-17676|-17496|-17487|-17482|-17468" .
	"|-17454|-17433|-17427|-17417|-17202|-17185|-16983|-16970|-16942|-16915|-16733|-16708|-16706|-16689|-16664" .
	"|-16657|-16647|-16474|-16470|-16465|-16459|-16452|-16448|-16433|-16429|-16427|-16423|-16419|-16412|-16407" .
	"|-16403|-16401|-16393|-16220|-16216|-16212|-16205|-16202|-16187|-16180|-16171|-16169|-16158|-16155|-15959" .
	"|-15958|-15944|-15933|-15920|-15915|-15903|-15889|-15878|-15707|-15701|-15681|-15667|-15661|-15659|-15652" .
	"|-15640|-15631|-15625|-15454|-15448|-15436|-15435|-15419|-15416|-15408|-15394|-15385|-15377|-15375|-15369" .
	"|-15363|-15362|-15183|-15180|-15165|-15158|-15153|-15150|-15149|-15144|-15143|-15141|-15140|-15139|-15128" .
	"|-15121|-15119|-15117|-15110|-15109|-14941|-14937|-14933|-14930|-14929|-14928|-14926|-14922|-14921|-14914" .
	"|-14908|-14902|-14894|-14889|-14882|-14873|-14871|-14857|-14678|-14674|-14670|-14668|-14663|-14654|-14645" .
	"|-14630|-14594|-14429|-14407|-14399|-14384|-14379|-14368|-14355|-14353|-14345|-14170|-14159|-14151|-14149" .
	"|-14145|-14140|-14137|-14135|-14125|-14123|-14122|-14112|-14109|-14099|-14097|-14094|-14092|-14090|-14087" .
	"|-14083|-13917|-13914|-13910|-13907|-13906|-13905|-13896|-13894|-13878|-13870|-13859|-13847|-13831|-13658" .
	"|-13611|-13601|-13406|-13404|-13400|-13398|-13395|-13391|-13387|-13383|-13367|-13359|-13356|-13343|-13340" .
	"|-13329|-13326|-13318|-13147|-13138|-13120|-13107|-13096|-13095|-13091|-13076|-13068|-13063|-13060|-12888" .
	"|-12875|-12871|-12860|-12858|-12852|-12849|-12838|-12831|-12829|-12812|-12802|-12607|-12597|-12594|-12585" .
	"|-12556|-12359|-12346|-12320|-12300|-12120|-12099|-12089|-12074|-12067|-12058|-12039|-11867|-11861|-11847" .
	"|-11831|-11798|-11781|-11604|-11589|-11536|-11358|-11340|-11339|-11324|-11303|-11097|-11077|-11067|-11055" .
	"|-11052|-11045|-11041|-11038|-11024|-11020|-11019|-11018|-11014|-10838|-10832|-10815|-10800|-10790|-10780" .
	"|-10764|-10587|-10544|-10533|-10519|-10331|-10329|-10328|-10322|-10315|-10309|-10307|-10296|-10281|-10274" .
	"|-10270|-10262|-10260|-10256|-10254";
	$_TDataKey = explode('|', $_DataKey);
	$_TDataValue = explode('|', $_DataValue);
	$_Data = (PHP_VERSION >= '5.0') ? array_combine($_TDataKey, $_TDataValue) : _Array_Combine($_TDataKey, $_TDataValue);
	arsort($_Data);
	reset($_Data);
	if ($_Code != 'gb2312')
	$_String = _U2_Utf8_Gb($_String);
	$_Res = '';
	for ($i = 0; $i < strlen($_String); $i++) 
	{
		$_P = ord(substr($_String, $i, 1));
		if ($_P > 160) 
		{
			$_Q = ord(substr($_String, ++$i, 1));
			$_P = $_P * 256 + $_Q - 65536;
		}
		$_Res .= _Pinyin($_P, $_Data);
	}
	//echo $_Res;
	$_Res = preg_replace("/[^a-z0-9\s]*/", '', $_Res);   //此处有改动
	return $_Res = preg_replace("/\s/", '-', $_Res);     //此处有改动
}
 
function _Pinyin($_Num, $_Data) 
{
	if ($_Num > 0 && $_Num < 160)
	return chr($_Num);
	elseif ($_Num < -20319 || $_Num > -10247)
	return '';
	else {
	foreach ($_Data as $k => $v) {
	if ($v <= $_Num)
	break;
	}
	return $k;
	}
}
function _U2_Utf8_Gb($_C) 
{
	$_String = '';
	if ($_C < 0x80)
	$_String .= $_C;
	elseif ($_C < 0x800) {
	$_String .= chr(0xC0 | $_C >> 6);
	$_String .= chr(0x80 | $_C & 0x3F);
	} elseif ($_C < 0x10000) {
	$_String .= chr(0xE0 | $_C >> 12);
	$_String .= chr(0x80 | $_C >> 6 & 0x3F);
	$_String .= chr(0x80 | $_C & 0x3F);
	} elseif ($_C < 0x200000) {
	$_String .= chr(0xF0 | $_C >> 18);
	$_String .= chr(0x80 | $_C >> 12 & 0x3F);
	$_String .= chr(0x80 | $_C >> 6 & 0x3F);
	$_String .= chr(0x80 | $_C & 0x3F);
	}
	return iconv('UTF-8', 'GB2312', $_String);
}
function _Array_Combine($_Arr1, $_Arr2) 
{
	for ($i = 0; $i < count($_Arr1); $i++)
	$_Res[$_Arr1[$i]] = $_Arr2[$i];
	return $_Res;
}
echo cn2pinyin('zhangsan\'s google 李四',1);

php全功能无变形图片裁剪(转)

转载自:http://hi.baidu.com/microji/item/548d23dbfda6d93be2108f03

很久以前写了一个php图片任意图片无变形裁剪到指定大小,发布在CSDN博客上,后来被phpchina采集去了,程序有明显漏洞,现在修改了一下,在扩展一些功能,如果需要图片裁剪,或生成缩略图,这个基本上没有问题,全部需要的功能都在里面,全部都是无变形的。

这里我划分为四种模式:
1,任意图片裁剪到指定大小,超过的,剧中裁剪,并且最大化缩放,不够的拉伸,
2,超过的剧中裁剪,而不足的,不拉伸,即只缩小,不放大裁剪,会产生补白,可以用png透明度来消除
3,保留全部图片信息。不裁剪,只缩放,不足的补白。
4,保留全部图片信息。不裁剪,只缩放,不足的不补白,产生的图片为实际有效像素大小,例如有个图片是600X600 现在要生成 120X100 那么缩放后的实际有效像素为100X100,所以只生成100X100的图片,而第三种模式则生成120X100的大小,并且有补白

全部代码:

<?php
 
 
/**
* Author : smallchicken
* Time   : 2009年6月8日16:46:05
* mode 1 : 强制裁剪,生成图片严格按照需要,不足放大,超过裁剪,图片始终铺满
* mode 2 : 和1类似,但不足的时候 不放大 会产生补白,可以用png消除。
* mode 3 : 只缩放,不裁剪,保留全部图片信息,会产生补白,
* mode 4 : 只缩放,不裁剪,保留全部图片信息,生成图片大小为最终缩放后的图片有效信息的实际大小,不产生补白
* 默认补白为白色,如果要使补白成透明像素,请使用SaveAlpha()方法代替SaveImage()方法
*
* 调用方法:
*
* $ic=new ImageCrop('old.jpg','afterCrop.jpg');
* $ic->Crop(120,80,2);
* $ic->SaveImage();
*        //$ic->SaveAlpha();将补白变成透明像素保存
* $ic->destory();
* 
*
*/
class ImageCrop{
 
var $sImage;
var $dImage;
var $src_file;
var $dst_file;
var $src_width;
var $src_height;
var $src_ext;
var $src_type;
 
function ImageCrop($src_file,$dst_file=''){
$this->src_file=$src_file;
$this->dst_file=$dst_file;
$this->LoadImage();
}
 
function SetSrcFile($src_file){
$this->src_file=$src_file;
}
 
function SetDstFile($dst_file){
$this->dst_file=$dst_file;
}
 
function LoadImage(){
list($this->src_width, $this->src_height, $this->src_type) = getimagesize($this->src_file);
switch($this->src_type) {
case IMAGETYPE_JPEG :
$this->sImage=imagecreatefromjpeg($this->src_file);
$this->ext='jpg';
break;
case IMAGETYPE_PNG :
$this->sImage=imagecreatefrompng($this->src_file);
$this->ext='png';
break;
case IMAGETYPE_GIF :
$this->sImage=imagecreatefromgif($this->src_file);
$this->ext='gif';
break;
default:
exit();
}
}
 
function SaveImage($fileName=''){
$this->dst_file=$fileName ? $fileName : $this->dst_file;
switch($this->src_type) {
case IMAGETYPE_JPEG :
imagejpeg($this->dImage,$this->dst_file,100);
break;
case IMAGETYPE_PNG :
imagepng($this->dImage,$this->dst_file);
break;
case IMAGETYPE_GIF :
imagegif($this->dImage,$this->dst_file);
break;
default:
break;
}
}
 
function OutImage(){
switch($this->src_type) {
case IMAGETYPE_JPEG :
header('Content-type: image/jpeg');
imagejpeg($this->dImage);
break;
case IMAGETYPE_PNG :
header('Content-type: image/png');
imagepng($this->dImage);
break;
case IMAGETYPE_GIF :
header('Content-type: image/gif');
imagegif($this->dImage);
break;
default:
break;
}
}
 
function SaveAlpha($fileName=''){
$this->dst_file=$fileName ? $fileName . '.png' : $this->dst_file .'.png';
imagesavealpha($this->dImage, true);
imagepng($this->dImage,$this->dst_file);
}
 
function OutAlpha(){
imagesavealpha($this->dImage, true);
header('Content-type: image/png');
imagepng($this->dImage);
}    
 
function destory(){
imagedestroy($this->sImage);
imagedestroy($this->dImage);
}
 
function Crop($dst_width,$dst_height,$mode=1,$dst_file=''){
if($dst_file) $this->dst_file=$dst_file;
$this->dImage = imagecreatetruecolor($dst_width,$dst_height);
 
$bg = imagecolorallocatealpha($this->dImage,255,255,255,127);
imagefill($this->dImage, 0, 0, $bg);
imagecolortransparent($this->dImage,$bg);
 
$ratio_w=1.0 * $dst_width / $this->src_width;
$ratio_h=1.0 * $dst_height / $this->src_height;
$ratio=1.0;
switch($mode){
case 1:        // always crop
if( ($ratio_w < 1 && $ratio_h < 1) || ($ratio_w > 1 && $ratio_h > 1)){
$ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($dst_width / $ratio);
$tmp_h = (int)($dst_height / $ratio);
$tmp_img=imagecreatetruecolor($tmp_w , $tmp_h);
$src_x = (int) (($this->src_width-$tmp_w)/2) ; 
$src_y = (int) (($this->src_height-$tmp_h)/2) ;    
imagecopy($tmp_img, $this->sImage, 0,0,$src_x,$src_y,$tmp_w,$tmp_h);    
imagecopyresampled($this->dImage,$tmp_img,0,0,0,0,$dst_width,$dst_height,$tmp_w,$tmp_h);
imagedestroy($tmp_img);
}else{
$ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($this->src_width * $ratio);
$tmp_h = (int)($this->src_height * $ratio);
$tmp_img=imagecreatetruecolor($tmp_w ,$tmp_h);
imagecopyresampled($tmp_img,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height);
$src_x = (int)($tmp_w - $dst_width) / 2 ; 
$src_y = (int)($tmp_h - $dst_height) / 2 ;    
imagecopy($this->dImage, $tmp_img, 0,0,$src_x,$src_y,$dst_width,$dst_height);
imagedestroy($tmp_img);
}
break;
case 2:        // only small
if($ratio_w < 1 && $ratio_h < 1){
$ratio = $ratio_w < $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($dst_width / $ratio);
$tmp_h = (int)($dst_height / $ratio);
$tmp_img=imagecreatetruecolor($tmp_w , $tmp_h);
$src_x = (int) ($this->src_width-$tmp_w)/2 ; 
$src_y = (int) ($this->src_height-$tmp_h)/2 ;    
imagecopy($tmp_img, $this->sImage, 0,0,$src_x,$src_y,$tmp_w,$tmp_h);    
imagecopyresampled($this->dImage,$tmp_img,0,0,0,0,$dst_width,$dst_height,$tmp_w,$tmp_h);
imagedestroy($tmp_img);
}elseif($ratio_w > 1 && $ratio_h > 1){
$dst_x = (int) abs($dst_width - $this->src_width) / 2 ; 
$dst_y = (int) abs($dst_height -$this->src_height) / 2;    
imagecopy($this->dImage, $this->sImage,$dst_x,$dst_y,0,0,$this->src_width,$this->src_height);
}else{
$src_x=0;$dst_x=0;$src_y=0;$dst_y=0;
if(($dst_width - $this->src_width) < 0){
$src_x = (int) ($this->src_width - $dst_width)/2;
$dst_x =0;
}else{
$src_x =0;
$dst_x = (int) ($dst_width - $this->src_width)/2;
}
 
if( ($dst_height -$this->src_height) < 0){
$src_y = (int) ($this->src_height - $dst_height)/2;
$dst_y = 0;
}else{
$src_y = 0;
$dst_y = (int) ($dst_height - $this->src_height)/2;
}
imagecopy($this->dImage, $this->sImage,$dst_x,$dst_y,$src_x,$src_y,$this->src_width,$this->src_height);
}
break;
case 3:        // keep all image size and create need size
if($ratio_w > 1 && $ratio_h > 1){
$dst_x = (int)(abs($dst_width - $this->src_width )/2) ; 
$dst_y = (int)(abs($dst_height- $this->src_height)/2) ;
imagecopy($this->dImage, $this->sImage, $dst_x,$dst_y,0,0,$this->src_width,$this->src_height);
}else{
$ratio = $ratio_w > $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($this->src_width * $ratio);
$tmp_h = (int)($this->src_height * $ratio);
$tmp_img=imagecreatetruecolor($tmp_w ,$tmp_h);
imagecopyresampled($tmp_img,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height);
$dst_x = (int)(abs($tmp_w -$dst_width )/2) ; 
$dst_y = (int)(abs($tmp_h -$dst_height)/2) ;
imagecopy($this->dImage, $tmp_img, $dst_x,$dst_y,0,0,$tmp_w,$tmp_h);
imagedestroy($tmp_img);
}
break;
case 4:        // keep all image but create actually size
if($ratio_w > 1 && $ratio_h > 1){
$this->dImage = imagecreatetruecolor($this->src_width,$this->src_height);
imagecopy($this->dImage, $this->sImage,0,0,0,0,$this->src_width,$this->src_height);
}else{
$ratio = $ratio_w > $ratio_h ? $ratio_h : $ratio_w;
$tmp_w = (int)($this->src_width * $ratio);
$tmp_h = (int)($this->src_height * $ratio);
$this->dImage = imagecreatetruecolor($tmp_w ,$tmp_h);
imagecopyresampled($this->dImage,$this->sImage,0,0,0,0,$tmp_w,$tmp_h,$this->src_width,$this->src_height);
}
break;
}
}// end Crop
 
 
}
?>