<?
class classThumb extends ThumbHandler {
}
/**
* åºæ¬å¾çå¤çï¼ç¨äºå®æå¾ç缩å
¥ï¼æ°´å°æ·»å
* 彿°´å°å¾è¶
è¿ç®æ å¾ç尺寸æ¶ï¼æ°´å°å¾è½èªå¨éåºç®æ å¾çè缩å°
* æ°´å°å¾å¯ä»¥è®¾ç½®è·èæ¯çå并度
*
* Copyright(c) 2005 by ustb99. All rights reserved
*
* To contact the author write to {@link mailto:hide@address.com}
*
* @author å¶ç¶
* @version $Id: thumb.class.php,v 1.9 2006/09/30 09:31:56 zengjian Exp $
* @package system
*/
/**
* ThumbHandler
* @access public
*/
/*
ä½¿ç¨æ¹æ³:
èªå¨è£å:
ç¨åºä¼æç
§å¾çç尺寸ä»ä¸é¨è£åæå¤§çæ£æ¹å½¢ï¼å¹¶æç®æ 尺寸è¿è¡ç¼©ç¥
$t->setSrcImg("img/test.jpg");
$t->setCutType(1);//è¿ä¸å¥å°±OKäº
$t->setDstImg("tmp/new_test.jpg");
$t->createImg(60,60);
æå·¥è£å:
ç¨åºä¼æç
§æå®çä½ç½®ä»æºå¾ä¸åå¾
$t->setSrcImg("img/test.jpg");
$t->setCutType(2);//ææä¸ºæå·¥è£å
$t->setSrcCutPosition(100, 100);// æºå¾èµ·ç¹åæ
$t->setRectangleCut(300, 200);// è£å尺寸
$t->setDstImg("tmp/new_test.jpg");
$t->createImg(300,200);
*/
class ThumbHandler {
var $dst_img;// ç®æ æä»¶
var $h_src; // å¾çèµæºå¥æ
var $h_dst;// æ°å¾å¥æ
var $h_mask;// æ°´å°å¥æ
var $img_create_quality = 100;// å¾ççæè´¨é
var $img_display_quality = 80;// å¾çæ¾ç¤ºè´¨é,é»è®¤ä¸º75
var $img_scale = 0;// å¾çç¼©æ¾æ¯ä¾
var $src_w = 0;// åå¾å®½åº¦
var $src_h = 0;// åå¾é«åº¦
var $dst_w = 0;// æ°å¾æ»å®½åº¦
var $dst_h = 0;// æ°å¾æ»é«åº¦
var $fill_w;// å¡«å
å¾å½¢å®½
var $fill_h;// å¡«å
å¾å½¢é«
var $copy_w;// æ·è´å¾å½¢å®½
var $copy_h;// æ·è´å¾å½¢é«
var $src_x = 0;// åå¾ç»å¶èµ·å§æ¨ªåæ
var $src_y = 0;// åå¾ç»å¶èµ·å§çºµåæ
var $start_x;// æ°å¾ç»å¶èµ·å§æ¨ªåæ
var $start_y;// æ°å¾ç»å¶èµ·å§çºµåæ
var $mask_word;// æ°´å°æå
var $mask_img;// æ°´å°å¾ç
var $mask_pos_x = 0;// æ°´å°æ¨ªåæ
var $mask_pos_y = 0;// æ°´å°çºµåæ
var $mask_offset_x = 5;// æ°´å°æ¨ªååç§»
var $mask_offset_y = 5;// æ°´å°çºµååç§»
var $font_w;// æ°´å°åä½å®½
var $font_h;// æ°´å°åä½é«
var $mask_w;// æ°´å°å®½
var $mask_h;// æ°´å°é«
var $mask_font_color = "#ffffff";// æ°´å°æåé¢è²
var $mask_font = 2;// æ°´å°åä½
var $font_size;// 尺寸
var $mask_position = 0;// æ°´å°ä½ç½®
var $mask_img_pct = 50;// å¾çåå¹¶ç¨åº¦,å¼è¶å¤§ï¼åå¹¶ç¨åºè¶ä½
var $mask_txt_pct = 50;// æååå¹¶ç¨åº¦,å¼è¶å°ï¼åå¹¶ç¨åºè¶ä½
var $img_border_size = 0;// å¾çè¾¹æ¡å°ºå¯¸
var $img_border_color;// å¾çè¾¹æ¡é¢è²
var $_flip_x=0;// 水平翻转次æ°
var $_flip_y=0;// åç´ç¿»è½¬æ¬¡æ°
var $cut_type=0;// åªåç±»å
var $img_type;// æä»¶ç±»å
// æä»¶ç±»åå®ä¹,å¹¶æåºäºè¾åºå¾çç彿°
var $all_type = array(
"jpg" => array("output"=>"imagejpeg"),
"gif" => array("output"=>"imagegif"),
"png" => array("output"=>"imagepng"),
"wbmp" => array("output"=>"image2wbmp"),
"jpeg" => array("output"=>"imagejpeg"));
/**
* æé 彿°
*/
function ThumbHandler()
{
$this->mask_font_color = "#ffffff";
$this->font = 2;
$this->font_size = 12;
}
/**
* åå¾å¾çç宽
*/
function getImgWidth($src)
{
return imagesx($src);
}
/**
* åå¾å¾ççé«
*/
function getImgHeight($src)
{
return imagesy($src);
}
/**
* 设置å¾ççæè·¯å¾
*
* @param string $src_img å¾ççæè·¯å¾
*/
function setSrcImg($src_img, $img_type=null)
{
if(!file_exists($src_img))
{
die("å¾çä¸åå¨");
}
if(!empty($img_type))
{
$this->img_type = $img_type;
}
else
{
$this->img_type = $this->_getImgType($src_img);
}
$this->_checkValid($this->img_type);
// file_get_contents彿°è¦æ±phpçæ¬>4.3.0
$src = '';
if(function_exists("file_get_contents"))
{
$src = file_get_contents($src_img);
}
else
{
$handle = fopen ($src_img, "r");
while (!feof ($handle))
{
$src .= fgets($fd, 4096);
}
fclose ($handle);
}
if(empty($src))
{
die("å¾çæºä¸ºç©º");
}
$this->h_src = @ImageCreateFromString($src);
$this->src_w = $this->getImgWidth($this->h_src);
$this->src_h = $this->getImgHeight($this->h_src);
}
/**
* 设置å¾ççæè·¯å¾
*
* @param string $dst_img å¾ççæè·¯å¾
*/
function setDstImg($dst_img)
{
$arr = explode('/',$dst_img);
$last = array_pop($arr);
$path = implode('/',$arr);
$this->_mkdirs($path);
$this->dst_img = $dst_img;
}
/**
* 设置å¾ççæ¾ç¤ºè´¨é
*
* @param string $n è´¨é
*/
function setImgDisplayQuality($n)
{
$this->img_display_quality = (int)$n;
}
/**
* 设置å¾çççæè´¨é
*
* @param string $n è´¨é
*/
function setImgCreateQuality($n)
{
$this->img_create_quality = (int)$n;
}
/**
* 设置æåæ°´å°
*
* @param string $word æ°´å°æå
* @param integer $font æ°´å°åä½
* @param string $color æ°´å°åä½é¢è²
*/
function setMaskWord($word)
{
$this->mask_word .= $word;
}
/**
* 设置åä½é¢è²
*
* @param string $color åä½é¢è²
*/
function setMaskFontColor($color="#ffffff")
{
$this->mask_font_color = $color;
}
/**
* 设置水å°åä½
*
* @param string|integer $font åä½
*/
function setMaskFont($font=2)
{
if(!is_numeric($font) && !file_exists($font))
{
die("å使件ä¸åå¨");
}
$this->font = $font;
}
/**
* 设置æååä½å¤§å°,ä»
对truetypeå使æ
*/
function setMaskFontSize($size = "12")
{
$this->font_size = $size;
}
/**
* 设置å¾çæ°´å°
*
* @param string $img æ°´å°å¾çæº
*/
function setMaskImg($img)
{
$this->mask_img = $img;
}
/**
* è®¾ç½®æ°´å°æ¨ªååç§»
*
* @param integer $x 横ååç§»é
*/
function setMaskOffsetX($x)
{
$this->mask_offset_x = (int)$x;
}
/**
* 设置水å°çºµååç§»
*
* @param integer $y 纵ååç§»é
*/
function setMaskOffsetY($y)
{
$this->mask_offset_y = (int)$y;
}
/**
* æå®æ°´å°ä½ç½®
*
* @param integer $position ä½ç½®,1:å·¦ä¸,2:å·¦ä¸,3:å³ä¸,0/4:å³ä¸
*/
function setMaskPosition($position=0)
{
$this->mask_position = (int)$position;
}
/**
* 设置å¾çåå¹¶ç¨åº¦
*
* @param integer $n åå¹¶ç¨åº¦
*/
function setMaskImgPct($n)
{
$this->mask_img_pct = (int)$n;
}
/**
* 设置æååå¹¶ç¨åº¦
*
* @param integer $n åå¹¶ç¨åº¦
*/
function setMaskTxtPct($n)
{
$this->mask_txt_pct = (int)$n;
}
/**
* 设置缩ç¥å¾è¾¹æ¡
*
* @param (ç±»å) (åæ°å) (æè¿°)
*/
function setDstImgBorder($size=1, $color="#000000")
{
$this->img_border_size = (int)$size;
$this->img_border_color = $color;
}
/**
* 水平翻转
*/
function flipH()
{
$this->_flip_x++;
}
/**
* åç´ç¿»è½¬
*/
function flipV()
{
$this->_flip_y++;
}
/**
* 设置åªåç±»å
*
* @param (ç±»å) (åæ°å) (æè¿°)
*/
function setCutType($type)
{
$this->cut_type = (int)$type;
}
/**
* 设置å¾çåªå
*
* @param integer $width ç©å½¢åªå
*/
function setRectangleCut($width, $height)
{
$this->fill_w = (int)$width;
$this->fill_h = (int)$height;
}
/**
* 设置æºå¾åªåèµ·å§åæ ç¹
*
* @param (ç±»å) (åæ°å) (æè¿°)
*/
function setSrcCutPosition($x, $y)
{
$this->src_x = (int)$x;
$this->src_y = (int)$y;
}
/**
* å建å¾ç,䏻彿°
* @param integer $a å½ç¼ºå°ç¬¬äºä¸ªåæ°æ¶ï¼æ¤åæ°å°ç¨ä½ç¾åæ¯ï¼
* å¦åä½ä¸ºå®½åº¦å¼
* @param integer $b å¾ç缩æ¾åçé«åº¦
*/
function createImg($a, $b=null)
{
$num = func_num_args();
if(1 == $num)
{
$r = (int)$a;
if($r < 1)
{
die("å¾çç¼©æ¾æ¯ä¾ä¸å¾å°äº1");
}
$this->img_scale = $r;
$this->_setNewImgSize($r);
}
if(2 == $num)
{
$w = (int)$a;
$h = (int)$b;
if(0 == $w)
{
die("ç®æ 宽度ä¸è½ä¸º0");
}
if(0 == $h)
{
die("ç®æ é«åº¦ä¸è½ä¸º0");
}
$this->_setNewImgSize($w, $h);
}
if($this->_flip_x%2!=0)
{
$this->_flipH($this->h_src);
}
if($this->_flip_y%2!=0)
{
$this->_flipV($this->h_src);
}
$this->_createMask();
$this->_output();
// éæ¾
if(imagedestroy($this->h_src) && imagedestroy($this->h_dst))
{
Return true;
}
else
{
Return false;
}
}
/**
* çææ°´å°,è°ç¨äºçææ°´å°æååæ°´å°å¾çä¸¤ä¸ªæ¹æ³
*/
function _createMask()
{
if($this->mask_word)
{
// è·ååä½ä¿¡æ¯
$this->_setFontInfo();
if($this->_isFull())
{
die("æ°´å°æåè¿å¤§");
}
else
{
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// å¡«å
èæ¯è²
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this->fill_w, $this->fill_h,
$this->copy_w, $this->copy_h);
$this->_createMaskWord($this->h_dst);
}
}
if($this->mask_img)
{
$this->_loadMaskImg();//å è½½æ¶ï¼åå¾å®½é«
if($this->_isFull())
{
// å°æ°´å°çæå¨åå¾ä¸åæ·
$this->_createMaskImg($this->h_src);
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// å¡«å
èæ¯è²
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this->fill_w, $this->start_y,
$this->copy_w, $this->copy_h);
}
else
{
// å建æ°å¾å¹¶æ·è´
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// å¡«å
èæ¯è²
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this->fill_w, $this->fill_h,
$this->copy_w, $this->copy_h);
$this->_createMaskImg($this->h_dst);
}
}
if(empty($this->mask_word) && empty($this->mask_img))
{
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// å¡«å
èæ¯è²
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this->fill_w, $this->fill_h,
$this->copy_w, $this->copy_h);
}
}
/**
* ç»è¾¹æ¡
*/
function _drawBorder()
{
if(!empty($this->img_border_size))
{
$c = $this->_parseColor($this->img_border_color);
$color = ImageColorAllocate($this->h_src,$c[0], $c[1], $c[2]);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$color);// å¡«å
èæ¯è²
}
}
/**
* çææ°´å°æå
*/
function _createMaskWord($src)
{
$this->_countMaskPos();
$this->_checkMaskValid();
$c = $this->_parseColor($this->mask_font_color);
$color = imagecolorallocatealpha($src, $c[0], $c[1], $c[2], $this->mask_txt_pct);
if(is_numeric($this->font))
{
imagestring($src,
$this->font,
$this->mask_pos_x, $this->mask_pos_y,
$this->mask_word,
$color);
}
else
{
imagettftext($src,
$this->font_size, 0,
$this->mask_pos_x, $this->mask_pos_y,
$color,
$this->font,
$this->mask_word);
}
}
/**
* çææ°´å°å¾
*/
function _createMaskImg($src)
{
$this->_countMaskPos();
$this->_checkMaskValid();
imagecopymerge($src,
$this->h_mask,
$this->mask_pos_x ,$this->mask_pos_y,
0, 0,
$this->mask_w, $this->mask_h,
$this->mask_img_pct);
imagedestroy($this->h_mask);
}
/**
* å 载水å°å¾
*/
function _loadMaskImg()
{
$mask_type = $this->_getImgType($this->mask_img);
$this->_checkValid($mask_type);
// file_get_contents彿°è¦æ±phpçæ¬>4.3.0
$src = '';
if(function_exists("file_get_contents"))
{
$src = file_get_contents($this->mask_img);
}
else
{
$handle = fopen ($this->mask_img, "r");
while (!feof ($handle))
{
$src .= fgets($fd, 4096);
}
fclose ($handle);
}
if(empty($this->mask_img))
{
die("æ°´å°å¾ç为空");
}
$this->h_mask = ImageCreateFromString($src);
$this->mask_w = $this->getImgWidth($this->h_mask);
$this->mask_h = $this->getImgHeight($this->h_mask);
}
/**
* å¾çè¾åº
*/
function _output()
{
$img_type = $this->img_type;
$func_name = $this->all_type[$img_type]['output'];
if(function_exists($func_name))
{
// 夿æµè§å¨,è¥æ¯IEå°±ä¸åé头
if(isset($_SERVER['HTTP_USER_AGENT']))
{
$ua = strtoupper($_SERVER['HTTP_USER_AGENT']);
if(!preg_match('/^.*MSIE.*\)$/i',$ua))
{
header("Content-type:$img_type");
}
}
$func_name($this->h_dst, $this->dst_img, $this->img_display_quality);
}
else
{
Return false;
}
}
/**
* åæé¢è²
*
* @param string $color åå
è¿å¶é¢è²
*/
function _parseColor($color)
{
$arr = array();
for($ii=1; $ii<strlen($color); $ii++)
{
$arr[] = hexdec(substr($color,$ii,2));
$ii++;
}
Return $arr;
}
/**
* 计ç®åºä½ç½®åæ
*/
function _countMaskPos()
{
if($this->_isFull())
{
switch($this->mask_position)
{
case 1:
// å·¦ä¸
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 2:
// å·¦ä¸
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
break;
case 3:
// å³ä¸
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 4:
// å³ä¸
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
break;
default:
// é»è®¤å°æ°´å°æ¾å°å³ä¸,åç§»æå®åç´
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
break;
}
}
else
{
switch($this->mask_position)
{
case 1:
// å·¦ä¸
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 2:
// å·¦ä¸
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
break;
case 3:
// å³ä¸
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
break;
case 4:
// å³ä¸
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
break;
default:
// é»è®¤å°æ°´å°æ¾å°å³ä¸,åç§»æå®åç´
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
break;
}
}
}
/**
* 设置åä½ä¿¡æ¯
*/
function _setFontInfo()
{
if(is_numeric($this->font))
{
$this->font_w = imagefontwidth($this->font);
$this->font_h = imagefontheight($this->font);
// è®¡ç®æ°´å°å使å 宽é«
$word_length = strlen($this->mask_word);
$this->mask_w = $this->font_w*$word_length;
$this->mask_h = $this->font_h;
}
else
{
$arr = imagettfbbox ($this->font_size,0, $this->font,$this->mask_word);
$this->mask_w = abs($arr[0] - $arr[2]);
$this->mask_h = abs($arr[7] - $arr[1]);
}
}
/**
* 设置æ°å¾å°ºå¯¸
*
* @param integer $img_w ç®æ 宽度
* @param integer $img_h ç®æ é«åº¦
*/
function _setNewImgSize($img_w, $img_h=null)
{
$num = func_num_args();
if(1 == $num)
{
$this->img_scale = $img_w;// 宽度ä½ä¸ºæ¯ä¾
$this->fill_w = round($this->src_w * $this->img_scale / 100) - $this->img_border_size*2;
$this->fill_h = round($this->src_h * $this->img_scale / 100) - $this->img_border_size*2;
// æºæä»¶èµ·å§åæ
$this->src_x = 0;
$this->src_y = 0;
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
// ç®æ 尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
}
if(2 == $num)
{
$fill_w = (int)$img_w - $this->img_border_size*2;
$fill_h = (int)$img_h - $this->img_border_size*2;
if($fill_w < 0 || $fill_h < 0)
{
die("å¾çè¾¹æ¡è¿å¤§ï¼å·²è¶
è¿äºå¾çç宽度");
}
$rate_w = $this->src_w/$fill_w;
$rate_h = $this->src_h/$fill_h;
switch($this->cut_type)
{
case 0:
// 妿åå¾å¤§äºç¼©ç¥å¾ï¼äº§ç缩å°ï¼å¦åä¸ç¼©å°
if($rate_w < 1 && $rate_h < 1)
{
$this->fill_w = (int)$this->src_w;
$this->fill_h = (int)$this->src_h;
}
else
{
if($rate_w >= $rate_h)
{
$this->fill_w = (int)$fill_w;
$this->fill_h = round($this->src_h/$rate_w);
}
else
{
$this->fill_w = round($this->src_w/$rate_h);
$this->fill_h = (int)$fill_h;
}
}
$this->src_x = 0;
$this->src_y = 0;
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
// ç®æ 尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
break;
// èªå¨è£å
case 1:
// 妿å¾çæ¯ç¼©å°åªåæè¿è¡æä½
if($rate_w >= 1 && $rate_h >=1)
{
if($this->src_w > $this->src_h)
{
$src_x = round($this->src_w-$this->src_h)/2;
$this->setSrcCutPosition($src_x, 0);
$this->setRectangleCut($fill_h, $fill_h);
$this->copy_w = $this->src_h;
$this->copy_h = $this->src_h;
}
elseif($this->src_w < $this->src_h)
{
$src_y = round($this->src_h-$this->src_w)/2;
$this->setSrcCutPosition(0, $src_y);
$this->setRectangleCut($fill_w, $fill_h);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_w;
}
else
{
$this->setSrcCutPosition(0, 0);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_w;
$this->setRectangleCut($fill_w, $fill_h);
}
}
else
{
$this->setSrcCutPosition(0, 0);
$this->setRectangleCut($this->src_w, $this->src_h);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
}
// ç®æ 尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
break;
// æå·¥è£å
case 2:
$this->copy_w = $this->fill_w;
$this->copy_h = $this->fill_h;
// ç®æ 尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
break;
default:
break;
}
}
// ç®æ æä»¶èµ·å§åæ
$this->start_x = $this->img_border_size;
$this->start_y = $this->img_border_size;
}
/**
* æ£æ¥æ°´å°å¾æ¯å¦å¤§äºçæåçå¾ç宽é«
*/
function _isFull()
{
Return ( $this->mask_w + $this->mask_offset_x > $this->fill_w
|| $this->mask_h + $this->mask_offset_y > $this->fill_h)
?true:false;
}
/**
* æ£æ¥æ°´å°å¾æ¯å¦è¶
è¿åå¾
*/
function _checkMaskValid()
{
if( $this->mask_w + $this->mask_offset_x > $this->src_w
|| $this->mask_h + $this->mask_offset_y > $this->src_h)
{
die("æ°´å°å¾ç尺寸大äºåå¾ï¼è¯·ç¼©å°æ°´å°å¾");
}
}
/**
* åå¾å¾çç±»å
*
* @param string $file_path æä»¶è·¯å¾
*/
function _getImgType($file_path)
{
$type_list = array("1"=>"gif","2"=>"jpg","3"=>"png","4"=>"swf","5" => "psd","6"=>"bmp","15"=>"wbmp");
if(file_exists($file_path))
{
$img_info = @getimagesize ($file_path);
if(isset($type_list[$img_info[2]]))
{
Return $type_list[$img_info[2]];
}
}
else
{
die("æä»¶ä¸åå¨,ä¸è½åå¾æä»¶ç±»å!");
}
}
/**
* æ£æ¥å¾çç±»åæ¯å¦åæ³,è°ç¨äºarray_key_exists彿°ï¼æ¤å½æ°è¦æ±
* phpçæ¬å¤§äº4.1.0
*
* @param string $img_type æä»¶ç±»å
*/
function _checkValid($img_type)
{
if(!array_key_exists($img_type, $this->all_type))
{
Return false;
}
}
/**
* ææå®è·¯å¾çæç®å½
*
* @param string $path è·¯å¾
*/
function _mkdirs($path)
{
$adir = explode('/',$path);
$dirlist = '';
$rootdir = array_shift($adir);
if(($rootdir!='.'||$rootdir!='..')&&!file_exists($rootdir))
{
@mkdir($rootdir);
}
foreach($adir as $key=>$val)
{
if($val!='.'&&$val!='..')
{
$dirlist .= "/".$val;
$dirpath = $rootdir.$dirlist;
if(!file_exists($dirpath))
{
@mkdir($dirpath);
@chmod($dirpath,0777);
}
}
}
}
/**
* åç´ç¿»è½¬
*
* @param string $src å¾çæº
*/
function _flipV($src)
{
$src_x = $this->getImgWidth($src);
$src_y = $this->getImgHeight($src);
$new_im = imagecreatetruecolor($src_x, $src_y);
for ($y = 0; $y < $src_y; $y++)
{
imagecopy($new_im, $src, 0, $src_y - $y - 1, 0, $y, $src_x, 1);
}
$this->h_src = $new_im;
}
/**
* 水平翻转
*
* @param string $src å¾çæº
*/
function _flipH($src)
{
$src_x = $this->getImgWidth($src);
$src_y = $this->getImgHeight($src);
$new_im = imagecreatetruecolor($src_x, $src_y);
for ($x = 0; $x < $src_x; $x++)
{
imagecopy($new_im, $src, $src_x - $x - 1, 0, $x, 0, 1, $src_y);
}
$this->h_src = $new_im;
}
}
/**
require_once('lib/thumb.class.php');
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
$t->setDstImg("tmp/new_test.jpg");
$t->setMaskImg("img/test.gif");
$t->setMaskPosition(1);
$t->setMaskImgPct(80);
$t->setDstImgBorder(4,"#dddddd");
// æå®ç¼©æ¾æ¯ä¾
$t->createImg(300,200);
require_once('lib/thumb.class.php');
$t = new ThumbHandler();
// åºæ¬ä½¿ç¨
$t->setSrcImg("img/test.jpg");
$t->setMaskWord("test");
$t->setDstImgBorder(10,"#dddddd");
// æå®ç¼©æ¾æ¯ä¾
$t->createImg(50);
equire_once('lib/thumb.class.php');
$t = new ThumbHandler();
// åºæ¬ä½¿ç¨
$t->setSrcImg("img/test.jpg");
$t->setMaskWord("test");
// æå®åºå®å®½é«
$t->createImg(200,200);
require_once('lib/thumb.class.php');
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
$t->setDstImg("tmp/new_test.jpg");
$t->setMaskWord("test");
// æå®åºå®å®½é«
$t->createImg(200,200);
require_once('lib/thumb.class.php');
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
// æå®å使件å°å
$t->setMaskFont("c:/winnt/fonts/arial.ttf");
$t->setMaskFontSize(20);
$t->setMaskFontColor("#ffff00");
$t->setMaskWord("test3333333");
$t->setDstImgBorder(99,"#dddddd");
$t->createImg(50);
require_once('lib/thumb.class.php');
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
$t->setMaskOffsetX(55);
$t->setMaskOffsetY(55);
$t->setMaskPosition(1);
//$t->setMaskPosition(2);
//$t->setMaskPosition(3);
//$t->setMaskPosition(4);
$t->setMaskFontColor("#ffff00");
$t->setMaskWord("test");
// æå®åºå®å®½é«
$t->createImg(50);
require_once('lib/thumb.class.php');
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
$t->setMaskFont("c:/winnt/fonts/simyou.ttf");
$t->setMaskFontSize(20);
$t->setMaskFontColor("#ffffff");
$t->setMaskTxtPct(20);
$t->setDstImgBorder(10,"#dddddd");
$text = "䏿";
$str = mb_convert_encoding($text, "UTF-8", "gb2312");
$t->setMaskWord($str);
$t->setMaskWord("test");
// æå®åºå®å®½é«
$t->createImg(50);
*/
?>