<?php


class system{
   
    /**
	 * $sourfile 源文件
	 * $wname 生成的文件名(不包括后缀)
	 */
function thumb($sourfile,$wname) {
	
	$arr=array();
    $wh=array();
	$wh['s']=array('w'=>120,'h'=>100); //小图
	$wh['m']=array('w'=>360,'h'=>300); //中等

	$imagetype = strtolower(str_replace('.', '', strrchr($sourfile, '.')));
	if (!$data = @getimagesize($sourfile))
	return false;

	if ($imagetype == 'gif') {
		$img = imagecreatefromgif($sourfile);
	} else
	if ($imagetype == 'jpg' || $imagetype == 'jpeg') {
		$img = imagecreatefromjpeg($sourfile);
	} else
	if ($imagetype == 'png') {
		$img = imagecreatefrompng($sourfile);
	} else {
		return false;
	}

	if (empty($img)) return false;

foreach($wh as $k=>$v){

	
$width = $v['w'];
$height = $v['h'];
	
	if($data[0]<=$width && $data[1]<=$height){
	continue;
}
    $arr[]=$wname.'_'.$k.'.jpg';
	$filename=ABSPATH.'uploads/temp/'.$wname.'_'.$k.'.jpg';

	$width = ($width > $data[0]) ? $data[0] : $width;
	$height = ($height > $data[1]) ? $data[1] : $height;
	$srcW = $data[0];
	$srcH = $data[1];
	if ($srcW * $width > $srcH * $height)
	$height = round($srcH * $width / $srcW);
	else
	$width = round($srcW * $height / $srcH);

	if (function_exists('imagecreatetruecolor')) {
		$new = imagecreatetruecolor($width, $height);
		ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $data[0], $data[1]);
	} else {
		$new = imagecreate($width, $height);
		ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $data[0], $data[1]);
	}
	ImageJPEG($new, $filename,90);
	ImageDestroy($new);
	}
	
	ImageDestroy($img);
	
	
	return $arr;
}

  function rands($length=10)
   {
        $output='';
        for ($a = 0; $a < $length; $a++) {
            $output .= chr(mt_rand(35, 126)); 
        }
        return $output;
    }  
   
}


?>