Source for file rainImage.php

Documentation is available at rainImage.php

  1. <?
  2.  
  3. /**  
  4.  * À̹ÌÁö Çڵ鸵
  5.  * @package com.rain
  6.  * @version 1.0
  7.  * @author http://cafen.net (outmind@cafen.net)
  8. */
  9. class rainImage {
  10.  
  11.     /**  
  12.      * ±âº» À̹ÌÁö
  13.      *
  14.      * @var resource 
  15.     */
  16.     var $img;
  17.  
  18.     /**  
  19.      * text_y ¸¶Áö¸· TEXT YÁÂÇ¥
  20.      *
  21.      * @var Int 
  22.     */
  23.     var $text_x = 0;
  24.  
  25.     /**  
  26.      * text_y ¸¶Áö¸· TEXT YÁÂÇ¥
  27.      *
  28.      * @var Int 
  29.     */
  30.     var $text_y = 0;
  31.  
  32.     /**  
  33.      * À̹ÌÁö ±âº» °æ·Î
  34.      *
  35.      * @var String 
  36.     */
  37.     var $base_root = null;
  38.  
  39.     /**  
  40.      * RGB2HUE Table
  41.      *
  42.      * @var Array 
  43.     */
  44.     var $base_rgb2hue = Array();
  45.  
  46.     /**  
  47.      * HUE2RGB Table
  48.      *
  49.      * @var Array 
  50.     */
  51.     var $base_hue2rgb = Array();
  52.  
  53.     /**
  54.      * »ý¼ºÀÚ
  55.      *
  56.      * @param  Int  À̹ÌÁö °¡·Î
  57.      * @param  Int À̹ÌÁö ¼¼·Î
  58.     */
  59.     function rainImage($destWidth 0$destHeight 0{
  60.         if ($destWidth && $destHeight 0
  61.             $this->img = $this->getImg($destWidth$destHeight);
  62.     }
  63.  
  64.     /**
  65.      *  Graphics2D °¡Á®¿À±â
  66.      *
  67.      * @return  resource 
  68.     */
  69.     function getGraphic(){
  70.          return $this->img;
  71.     }
  72.  
  73.     /**
  74.      *  ±âº» ÀÛ¾÷ °ø°£ °¡Á®¿À±â
  75.      *
  76.      * @return  String base Root dir
  77.     */
  78.     function getBaseRoot(){
  79.         if ($this->base_root == null)
  80.             $this->base_root = rainUtil::getConf("path_uploads");
  81.         return $this->base_root;
  82.     }
  83.  
  84.     /**
  85.      *  À̹ÌÁö »ý¼º
  86.      *
  87.      * @param  Int  À̹ÌÁö °¡·Î
  88.      * @param  Int À̹ÌÁö ¼¼·Î
  89.      * @return  resource    BufferedImage
  90.     */
  91.     function getImg($w$h,$with_transparent false){
  92.         $img imagecreatetruecolor ($w$h);
  93.         if ($with_transparent{
  94.             $white $this -> getColor($img'#005282');
  95.             imagefilledrectangle($img00$w$h$white);
  96.             imagecolortransparent($img$white);
  97.         }
  98.         return $img;
  99.     }
  100.  
  101.     /**
  102.      *  À̹ÌÁö ºÒ·¯¿À±â
  103.      *
  104.      * @param  String  À̹ÌÁö ÆÄÀϸí
  105.      * @param  String À̹ÌÁö °¡Á®¿À±â ½ÇÆÐ½Ã °¡Á®¿Ã À̹ÌÁö
  106.      * @return  resource    BufferedImage
  107.     */
  108.     function load($fileName$onErrorimg ""){
  109.         $src_im null;
  110.         if ($fileName != '' && file_exists($this->getBaseRoot($fileName)) {
  111.             if ($img_info @getimagesize($this->getBaseRoot($fileName)) {
  112.                 switch ($img_info[2]{
  113.                     case "2"
  114.                         $src_im ImageCreateFromJPEG($this->getBaseRoot($fileName)
  115.                         break;
  116.                     case "1"
  117.                         $src_im ImageCreateFromGIF($this->getBaseRoot($fileName)
  118.                         break;
  119.                     case "3"
  120.                         $src_im ImageCreateFromPNG($this->getBaseRoot($fileName)
  121.                         break;
  122.                     default 
  123.                         if ($onErrorimg != ""
  124.                             $src_im $this->load($onErrorimg);
  125.                         break;            
  126.                 }
  127.             else if ($onErrorimg != ""
  128.                 $src_im $this->load($onErrorimg);
  129.         
  130.         if ($src_im == null)
  131.             $src_im $this->getImg(100,100);
  132.         return $src_im;
  133.     }
  134.  
  135.     /**
  136.      * À̹ÌÁö ÀÚµ¿ºÒ·¯¿À±â
  137.      *
  138.      * @param  String  À̹ÌÁö ÆÄÀϸí
  139.      * @return  resource    BufferedImage
  140.     */
  141.     function autoLoad($fileName){
  142.         if ($fileName != '' && file_exists($this->getBaseRoot('thumb/'.$fileName.'.png')) 
  143.             return $this->load('thumb/'.$fileName.'.png');
  144.         else if ($img_info @getimagesize($this->getBaseRoot($fileName)) {
  145.             if $img_info[01024 || $img_info[11024{
  146.                 $img =     $this->load($fileName);
  147.                 $this->img = $img $this->resizeMax($img1024);
  148.                 if ($this->save('thumb/'.$fileName.'.png')) {
  149.                     $fm new rainFileManager($fileName);
  150.                     $fm->add('thumb/'.$fileName.'.png');
  151.                 }    
  152.                 return $img;
  153.             else 
  154.                 return $this->load($fileName"imgstyle/img_error.jpg");
  155.         else 
  156.             return $this->load($fileName"imgstyle/img_error.jpg");
  157.     }
  158.  
  159.     /**
  160.      * À̹ÌÁö ÀÚ¸£±â
  161.      *
  162.      * @param  resource  À̹ÌÁö
  163.      * @param  Int  °¡·Î¼¼·Î ºñÀ²
  164.      * @param  Int  ±âÁØÀ§Ä¡ (0 : Á»ó´Ü, 1: Áß°£»ó´Ü, 2: ¿ì»ó´Ü, 3 : ÁÂÁß°£, 4 : Áß°£Áß°£, 5 : ¿ìÁß°£, 6 : ÁÂÇÏ´Ü, 7 : Áß°£ÇÏ´Ü, 8: ¿ìÇÏ´Ü)
  165.      * @return  resource    BufferedImage
  166.     */
  167.     function trim($img$rate$pos){
  168.         $ow $tw imagesx($img;
  169.         $oh $th imagesy($img);
  170.         if ($ow/$oh >= $rate)
  171.             $tw round($oh $rate);
  172.         else
  173.             $th round($ow $rate);
  174.         $padding_x $padding_y 0;
  175.         switch($pos{
  176.             case :
  177.                 $padding_x 0;
  178.                 $padding_y 0;
  179.                 break;
  180.             case :
  181.                 $padding_x round(($ow $tw)/2);
  182.                 $padding_y 0;
  183.                 break;
  184.             case :
  185.                 $padding_x ($ow $tw);
  186.                 $padding_y 0;
  187.                 break;
  188.             case :
  189.                 $padding_x 0;
  190.                 $padding_y round(($oh $th)/2);
  191.                 break;
  192.             case :
  193.                 $padding_x round(($ow $tw)/2);
  194.                 $padding_y round(($oh $th)/2);
  195.                 break;
  196.             case :
  197.                 $padding_x $ow $tw;
  198.                 $padding_y round(($oh $th)/2);
  199.                 break;
  200.             case :
  201.                 $padding_x 0;
  202.                 $padding_y $oh $th;
  203.                 break;
  204.             case :
  205.                 $padding_x round(($ow $tw)/2);
  206.                 $padding_y $oh $th;
  207.                 break;
  208.             case :
  209.                 $padding_x $ow $tw;
  210.                 $padding_y $oh $th;
  211.                 break;
  212.         }
  213.         return $this->getSubimage($img,$padding_x,$padding_y,$tw,$th);
  214.     }
  215.     
  216.     /**
  217.      *  ºÎºÐ À̹ÌÁö °¡Á®¿À±â
  218.      *
  219.      * @param  resource  ´ë»ó À̹ÌÁö
  220.      * @param  Int  X ÁÂÇ¥
  221.      * @param  Int  Y ÁÂÇ¥
  222.      * @param  Int  °¡·ÎÅ©±â
  223.      * @param  Int  ¼¼·ÎÅ©±â
  224.      * @param  Boolean  Åõ¸í¼³Á¤¿©ºÎ
  225.      * @return  resource    BufferedImage
  226.     */
  227.     function getSubimage($img$x$y$w$h$with_transparent false{
  228.         $base_img $this->getImg($w$h$with_transparent);
  229.         imagecopy ($base_img$img00$x$y$w$h);
  230.         return $base_img;
  231.     }
  232.  
  233.     /**
  234.      *  ¼¶³×ÀÏ À̹ÌÁö ¸¸µé±â thumb/À̹ÌÁöÆÄÀϰæ·Î¸í_À̹ÌÁöÈ¿°ú.png
  235.      *  F([a-z]+)([0-9]+)([MDT])S=(.+)= : 1 ÇÁ·¹ÀÓÀû¿ë (base, box, cap, cross, dashed, rain, saw, shadow, shasowbox)
  236.      *  F([a-z]+)([0-9]+)([MDT])S=(.+)= : 2 ÇÁ·¹ÀÓ ¿©¹é
  237.      *  F([a-z]+)([0-9]+)([MDT])S=(.+)= : 3 »çÁø ÃÔ¿µÁ¤º¸( M : »çÁø±â±âÁ¾, D:ÃÔ¿µÀÏÀÚ, T : ³ëÃâÁ¤º¸)
  238.      *  F([a-z]+)([0-9]+)([MDT])S=(.+)= : 4 »çÁø½ÎÀÎÃß°¡
  239.      *  R[0-3] : »çÁøÈ¸Àü [0 : ÀÚµ¿È¸Àü, 1: 90µµ, 2: 180µµ, 3: 270 µµ]
  240.      *  M([0-9]+)  : ÀåÃà ÃÖ´ë±æÀÌ
  241.      *  A([0-9]+)  : »ö»ó º¯°æ
  242.      *  T([0-9]+)  : »çÁø Æ®¸²¹Ö, 100À» ±âÁØÀ¸·Î 100 ÀÌÇϴ ¼¼·Î°¡ Å«»çÁø, 100 ÀÌ»óÀº °¡·Î°¡ Å«»çÁø 50 ÀÇ °æ¿ì °¡·Î/¼¼·Î ÀÌ 0.5 À» ¶æÇÔ
  243.      *  G  : ±×·¹ÀÌ ½ºÄÉÀÏ
  244.      *  N  : ³×°¡Æ¼ºê»çÁø
  245.      *  B([0-9]+)  : ºí·¯ ¹× »þÆÝ È¿°ú 10À» ±âÁØÀ¸·Î 10 ÀÌÇϴ ºí·¯, 10 ÀÌ»óÀº »çÆÝ
  246.      *  S([0-9]+)  : »þÆÝ È¿°ú(¹Ì»ç¿ë¿¹Á¤)
  247.      *  E([0-9]+)  : ¿¡Áö È¿°ú(¼ýÀÚ°¡ Å¬¼ö·Ï ¼±ÀÌ ºÐ¸íÇÔ)
  248.      *  W([0-9]+)  : È­ÀÌÆ® ¹ß¶õ½º (100 À» ±âÁØÀ¸·Î 100 ÀÌÇϴ ¾îµÓ°Ô 100 ÀÌ»óÀº ¹à°Ô
  249.      *  C([0-9]+)  : ÄÜÆ®¶ó½ºÆ® (100 À» ±âÁØÀ¸·Î 100 ÀÌÇϴ ¼±¸íÇϰԠ100 ÀÌ»óÀº ¸ðÈ£ÇϰÔ
  250.      *
  251.      * @param  String      ¼¶³×ÀÏ ¸í
  252.      * @return  Boolean    ¼º°ø¿©ºÎ
  253.     */
  254.     function makeThumb($fileName){
  255.         $img_name $imgeffect $frameeffect $skineffect $img_type "";
  256.         $exif null;
  257.         if (file_exists($this->getBaseRoot($fileName)) {
  258.             return true;
  259.         else {
  260.             $render_server rainUtil::getConf("domain_render");
  261.             if ($render_server != ''{
  262.                 $remotefile new rainFile($this->getBaseRoot());
  263.                 $tmp_filename $remotefile->remote_Copy($render_server."thumb/".$fileName"junk/""tmp");
  264.                 if ($tmp_filename == ''  || !rainUtil::file_exists($tmp_filename)) 
  265.                     $tmp_filename $remotefile->remote_Copy($render_server."thumb/".$fileName"junk/""tmp");
  266.                 if ($tmp_filename != '' && rainUtil::file_exists($tmp_filename)) {
  267.                     if (rainUtil::checkDir($this->getBaseRoot()$fileName)) 
  268.                         rainUtil::rename($tmp_filename$fileName);
  269.                 }
  270.                 if (rainUtil::file_exists($fileName)) 
  271.                     return true;
  272.                 else
  273.                     return false;
  274.             else {
  275.                 $reg Array();
  276.                 if (rainUtil::find("^thumb/(.+)_([=a-zA-Z0-9_]+)\.(png|jpg|gif)"$fileName,&$reg|| rainUtil::find("^(.+)_([=a-zA-Z0-9_]+)\.(png|jpg|gif)"$fileName&$reg)) {
  277.                     
  278.                     $img_name $reg[1];
  279.                     $imgeffect $reg[2];
  280.                     $img_type $reg[3];
  281.                     if (rainUtil::find("(.*)(K[0-9]+.*)"$imgeffect&$reg)) {
  282.                         $imgeffect $reg[1];
  283.                         $skineffect $reg[2];
  284.                     else if (rainUtil::find("(.+)(F[a-z]+[0-9]+.+)"$imgeffect&$reg)) {
  285.                         $imgeffect $reg[1];
  286.                         $frameeffect $reg[2];
  287.                     }
  288.                     if (rainUtil::find("R0"$imgeffect)) {
  289.                         $exif new rainExif($img_name);    
  290.                         $imgeffect rainUtil::replace("R0""R" $exif->getRotate()$imgeffect);
  291.                     }
  292.     
  293.                     $img $this->autoLoad($img_name);
  294.     
  295.                     if (imagesx($img1024)
  296.                         $img $this->resize($img1024);
  297.                     if ($imgeffect != "")
  298.                         $img $this->getImgEffect($img$imgeffect);
  299.                     if ($skineffect != ""{
  300.                         if ($exif == null)
  301.                             $exif new rainExif($img_name);    
  302.                         $img $this->getSkinEffect($img$skineffect$exif);
  303.                     else if ($frameeffect != ""{
  304.                         if ($exif == null)
  305.                             $exif new rainExif($img_name);    
  306.                         $img $this->getFrameEffect($img$frameeffect$exif);
  307.                     
  308.                     $this->img = $img;
  309.                     if ($this->save($fileName$img_type)) {
  310.                          if (rainUtil::find("^thumb/"$fileName)) {
  311.                             $fm new rainFileManager($img_name);
  312.                             $fm->add($fileName);
  313.                         }
  314.                         return true;
  315.                     else 
  316.                         return false;
  317.                 else 
  318.                     return false;
  319.             }
  320.         }
  321.     }        
  322.  
  323.     /**
  324.      *  ¼¶³×ÀÏ À̹ÌÁö ¸¸µé°í À¥À¸·Î Àü¼Û
  325.      *
  326.      * @param  String  ¼¶³×ÀÏ ¸í
  327.     */
  328.     function showThumb($fileName){
  329.         if ($this->makeThumb($fileName))
  330.             $this->show($fileName);
  331.     }
  332.  
  333.     /**
  334.      *  ÇÁ·¹ÀÓ È¿°ú
  335.      *  F([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 1 ÇÁ·¹ÀÓÀû¿ë (base, box, cap, cross, dashed, rain, saw, shadow, shasowbox)
  336.      *  F([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 2 ÇÁ·¹ÀÓ ¿©¹é
  337.      *  F([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 3 »çÁø ÃÔ¿µÁ¤º¸( M : »çÁø±â±âÁ¾, D:ÃÔ¿µÀÏÀÚ, T : ³ëÃâÁ¤º¸)
  338.      *  F([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 4 »çÁø½ÎÀÎÃß°¡ S : °ü¸®ÀÚ°¡ ÁöÁ¤¼º ¾Õ÷ÀÚ µÚ÷ÀÚ Ãß°¡, B: base64 ·Î encode ½ÃŲ ¹®ÀÚ¿­
  339.      *
  340.      * @param  resource      ´ë»ó À̹ÌÁö
  341.      * @param  String          ÇÁ·¹ÀÓÈ¿°ú
  342.      * @param  rainExif          »çÁøÀÇ Exif Á¤º¸
  343.      * @return  resource    BufferedImage
  344.     */
  345.     function getFrameEffect($img$effect$exif null){
  346.         $img_style $sign $pic_modelinfo $pic_dateinfo $pic_takeinfo "";
  347.         $fontcolor "#464646";
  348.         $addheight $addwidth $img_padding 0;
  349.         $reg Array();
  350.         if (rainUtil::find("F([a-z]+)([0-9]+)"$effect&$reg)) {
  351.             $img_style $reg[1];
  352.             $img_padding rainUtil::string2Int($reg[2]);
  353.             $addwidth $addheight += $img_padding 2;
  354.         }
  355.         if (rainUtil::find("S=([a-zA-Z0-9=]+)="$effect&$reg)) 
  356.             $sign $this->getSign($reg[1]);
  357.         else if (rainUtil::find("B=([a-zA-Z0-9=]+)="$effect&$reg)) 
  358.             $sign rainUtil::base64_decode($reg[1]);
  359.         if ($sign != "")
  360.             $addheight += 15;
  361.         if (rainUtil::find("M"$effect)) {
  362.             $pic_modelinfo $exif->getModel();
  363.             if ($pic_modelinfo != "")
  364.                 $addheight += 15;
  365.         }
  366.         if (rainUtil::find("D"$effect)) {
  367.             $pic_dateinfo $exif->getDatetime();
  368.             if ($pic_dateinfo != "")
  369.                 $addheight += 15;
  370.         }
  371.         if (rainUtil::find("T"$effect)) {
  372.             $pic_takeinfo $exif->getInfo();
  373.             if ($pic_takeinfo != "")
  374.                 $addheight += 15;
  375.         }
  376.                 
  377.         $frmWidth imagesx($img$addwidth ;
  378.         $frmHeight imagesy($img$addheight;
  379.         
  380.         $this->img = $this->getImg($frmWidth$frmHeight);
  381.         
  382.         if ($img_style != "" && $img_style != "none")
  383.             $this->setFrame($img_style);
  384.         $this->setImg($img$img_padding);
  385.         if ($sign != ""
  386.             $this->setText($sign$fontcolor);
  387.         if ($pic_modelinfo != ""
  388.             $this->setText($pic_modelinfo$fontcolor);
  389.         if ($pic_takeinfo != ""
  390.             $this->setText($pic_takeinfo$fontcolor);
  391.         if ($pic_dateinfo != ""
  392.             $this->setText($pic_dateinfo$fontcolor);
  393.         return $this->img;
  394.     }
  395.  
  396.     /**
  397.      *  ½ºÅ² È¿°ú
  398.      *  K([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 1 ÇÁ·¹ÀÓÀû¿ë (base, box, cap, cross, dashed, rain, saw, shadow, shasowbox)
  399.      *  K([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 2 ÇÁ·¹ÀÓ ¿©¹é
  400.      *  K([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 3 »çÁø ÃÔ¿µÁ¤º¸( M : »çÁø±â±âÁ¾, D:ÃÔ¿µÀÏÀÚ, T : ³ëÃâÁ¤º¸)
  401.      *  K([a-z]+)([0-9]+)([MDT])[SB]=(.+)= : 4 »çÁø½ÎÀÎÃß°¡ S : °ü¸®ÀÚ°¡ ÁöÁ¤¼º ¾Õ÷ÀÚ µÚ÷ÀÚ Ãß°¡, B: base64 ·Î encode ½ÃŲ ¹®ÀÚ¿­
  402.      *
  403.      * @param  resource      ´ë»ó À̹ÌÁö
  404.      * @param  String          ÇÁ·¹ÀÓÈ¿°ú
  405.      * @param  rainExif          »çÁøÀÇ Exif Á¤º¸
  406.      * @return  resource    BufferedImage
  407.     */
  408.     function getSkinEffect($img$effect$exif null){
  409.         $img_style $sign $pic_modelinfo $pic_dateinfo $pic_takeinfo "";
  410.         $fontcolor "#464646";
  411.         $reg Array();
  412.         if (rainUtil::find("K([0-9]+)"$effect&$reg)) 
  413.             $img_style $reg[1];
  414.         if (rainUtil::find("S=([a-zA-Z0-9=]+)="$effect&$reg)) 
  415.             $sign $this->getSign($reg[1]);
  416.         else if (rainUtil::find("B=([a-zA-Z0-9=]+)="$effect&$reg)) 
  417.             $sign rainUtil::base64_decode($reg[1]);
  418.         if (rainUtil::find("M"$effect)) 
  419.             $pic_modelinfo $exif->getModel();
  420.         if (rainUtil::find("D"$effect)) 
  421.             $pic_dateinfo $exif->getDatetime();
  422.         if (rainUtil::find("T"$effect)) 
  423.             $pic_takeinfo $exif->getInfo();
  424.         $text Array();
  425.         if ($sign != '')
  426.             $text[$sign;
  427.         if ($pic_modelinfo != '')
  428.             $text[$pic_modelinfo;
  429.         if ($pic_takeinfo != '')
  430.             $text[$pic_takeinfo;
  431.         if ($pic_dateinfo != '')
  432.             $text[$pic_dateinfo;
  433.         if (count($text))
  434.             $img $this->addText($img$text5);
  435.         if ($img_style != '')
  436.             $img $this->setSkin($img$img_style);
  437.         return $img;
  438.     }
  439.  
  440.     /**
  441.      *  À̹ÌÁö ½ÎÀΠ¹®ÀÚ °¡Á®¿À±â
  442.      *
  443.      * @param  String     ±âº» ¹®ÀÚ
  444.      * @return  String        À̹ÌÁö½ÎÀÎ
  445.     */
  446.     function getSign($sign){
  447.         return rainUtil::getConf("imgsign_pre"$sign rainUtil::getConf("imgsign_tail");
  448.     }
  449.  
  450.     /**
  451.      *  À̹ÌÁö È¿°úÁÖ±â
  452.      *  R[0-3] : »çÁøÈ¸Àü [0 : ÀÚµ¿È¸Àü, 1: 90µµ, 2: 180µµ, 3: 270 µµ]
  453.      *  M([0-9]+)  : ÀåÃà ÃÖ´ë±æÀÌ
  454.      *  A([0-9]+)  : »ö»ó º¯°æ
  455.      *  T([0-9]+)  : »çÁø Æ®¸²¹Ö, 100À» ±âÁØÀ¸·Î 100 ÀÌÇϴ ¼¼·Î°¡ Å«»çÁø, 100 ÀÌ»óÀº °¡·Î°¡ Å«»çÁø 50 ÀÇ °æ¿ì °¡·Î/¼¼·Î ÀÌ 0.5 À» ¶æÇÔ
  456.      *  G  : ±×·¹ÀÌ ½ºÄÉÀÏ
  457.      *  N  : ³×°¡Æ¼ºê»çÁø
  458.      *  B([0-9]+)  : ºí·¯ ¹× »þÆÝ È¿°ú 10À» ±âÁØÀ¸·Î 10 ÀÌÇϴ ºí·¯, 10 ÀÌ»óÀº »çÆÝ
  459.      *  S([0-9]+)  : »þÆÝ È¿°ú(¹Ì»ç¿ë¿¹Á¤)
  460.      *  E([0-9]+)  : ¿¡Áö È¿°ú(¼ýÀÚ°¡ Å¬¼ö·Ï ¼±ÀÌ ºÐ¸íÇÔ)
  461.      *  W([0-9]+)  : È­ÀÌÆ® ¹ß¶õ½º (100 À» ±âÁØÀ¸·Î 100 ÀÌÇϴ ¾îµÓ°Ô 100 ÀÌ»óÀº ¹à°Ô
  462.      *  C([0-9]+)  : ÄÜÆ®¶ó½ºÆ® (100 À» ±âÁØÀ¸·Î 100 ÀÌÇϴ ¼±¸íÇϰԠ100 ÀÌ»óÀº ¸ðÈ£ÇϰÔ
  463.      *
  464.      * @param  resource      ´ë»ó À̹ÌÁö
  465.      * @param  String            À̹ÌÁö È¿°ú
  466.      * @return  resource    BufferedImage
  467.     */
  468.     function getImgEffect($img$effect){
  469.         $reg array();
  470.         if (rainUtil::find("R([0-9])"$effect&$reg)) 
  471.             $img  $this->setRotate($imgrainUtil::string2Int($reg[1]));
  472.         $hue 0;
  473.         $sat 100;
  474.         $bri 100;
  475.         if (rainUtil::find("A([0-9]+)"$effect&$reg)) 
  476.             $sat rainUtil::string2Int($reg[1]);
  477.         if (rainUtil::find("H([0-9]+)"$effect&$reg)) 
  478.             $hue rainUtil::string2Int($reg[1]);
  479.         if (rainUtil::find("W([0-9]+)"$effect&$reg)) 
  480.             $bri rainUtil::string2Int($reg[1]);
  481.         if ($sat != 100 || $hue != 0)
  482.             $img  $this->effectHSB($img$hue,$sat ,$bri);
  483.         else if ($bri != 100)
  484.             $img  $this->effectBrighten($img$bri);
  485.         
  486.         if (rainUtil::find("M([0-9]+)"$effect&$reg)) 
  487.             $img  $this->resizeMax($imgrainUtil::string2Int($reg[1]));    
  488.         if (rainUtil::find("T([0-9]+)"$effect&$reg)) 
  489.             $img  $this->trim($imgrainUtil::string2Int($reg[1])/1004);    
  490.         if (rainUtil::find("G"$effect&$reg)) 
  491.             $img  $this->effectGray($img);    
  492.         if (rainUtil::find("N"$effect&$reg)) 
  493.             $img  $this->effectReverse($img);    
  494.         if (rainUtil::find("B([0-9]+)"$effect&$reg)) 
  495.             $img  $this->effectBlur($imgrainUtil::string2Int($reg[1]));
  496.         if (rainUtil::find("S([0-9])"$effect&$reg)) 
  497.             $img  $this->effectSharpen($imgrainUtil::string2Int($reg[1]));
  498.         if (rainUtil::find("E([0-9])"$effect&$reg)) 
  499.             $img  $this->effectEdge($imgrainUtil::string2Int($reg[1]));
  500.         if (rainUtil::find("C([0-9]+)"$effect&$reg)) 
  501.             $img  $this->effectContrast($imgrainUtil::string2Int($reg[1]));
  502.         return $img;
  503.     }    
  504.  
  505.     /**
  506.      *  ÇÔ¼ö »ç¿ë°¡´É¿©ºÎ(imagefilter)
  507.      *
  508.      * @param  String     ÇÔ¼ö¸í
  509.      * @return  Boolean    »ç¿ë°¡´É¿©ºÎ
  510.     */
  511.     function checkFun($funcName){
  512.         return @function_exists($funcName);
  513.     }
  514.  
  515.     /**
  516.      *  À̹ÌÁö ÀÌÆåÆ®ÁÖ±â
  517.      *
  518.      * @param  resource  ´ë»ó À̹ÌÁö
  519.      * @return  resource    BufferedImage
  520.     */
  521.     function effectEnd($img){
  522.         return $img;
  523.     }
  524.  
  525.     /**
  526.      *  ¿¡Áö È¿°úÁÖ±â
  527.      *
  528.      * @param  resource  ´ë»ó À̹ÌÁö
  529.      * @param  Int      ÂüÁ¶ºñÀ²
  530.      * @return  resource    BufferedImage
  531.     */
  532.     function effectEdge($img$rate){
  533.         if ($rate == 0return $img;
  534.         if ($this->checkFun("imagefilter")) {
  535.             $rate--;
  536.             imagefilter($imgIMG_FILTER_EDGEDETECT);
  537.             return $this->effectEdge($img$rate);
  538.         else {
  539.             $this->filterEdge($img$rate);
  540.             return $img;
  541.         }
  542.     }
  543.  
  544.     /**
  545.      *  »ö»ó È¿°úÁÖ±â
  546.      *
  547.      * @param  resource      ´ë»ó À̹ÌÁö
  548.      * @param  Int              ÂüÁ¶ºñÀ²
  549.      * @return  resource    BufferedImage
  550.     */
  551.     function effectColor($img$rate){
  552.         $rate $rate 100;
  553.         if ($rate == 0return $img;
  554.         if ($this->checkFun("imagefilter")) {
  555.             $rate max(-255min($rate255));
  556.             imagefilter($imgIMG_FILTER_COLORIZE$rate $rate$rate);
  557.             return $img;
  558.         else {
  559.             $this->filterColor($img$rate);
  560.             return $img;
  561.         }
  562.     }
  563.  
  564.     /**
  565.      *  TrueColor to paletteColor
  566.      *
  567.      * @param  resource      ´ë»ó À̹ÌÁö
  568.      * @param  Int                »ö»ó¼ö
  569.      * @return  resource    BufferedImage
  570.     */
  571.     function true2PaletteColor($img$ncolors){
  572.         if (imageistruecolor($img)) 
  573.             ImageTrueColorToPalette$imgfalse$ncolors );
  574.         return $img;    
  575.     }
  576.  
  577.     /**
  578.      *  paletteColor to TrueColor
  579.      *
  580.      * @param  resource  ´ë»ó À̹ÌÁö
  581.      * @return  resource    BufferedImage
  582.     */
  583.     function palette2TrueColor($img){
  584.         if (!imageistruecolor($img)) {
  585.             $width imagesx($img );
  586.             $height imagesy($img);
  587.             $colors_handle ImageCreateTrueColor$width$height );
  588.             ImageCopy$colors_handle$img0000$width$height);
  589.             $img $colors_handle;
  590.         }
  591.         return $img;    
  592.     }
  593.  
  594.     /**
  595.      * Ã¤µµ, Hue È¿°úÁÖ±â
  596.      *
  597.      * @param  resource      ´ë»ó À̹ÌÁö
  598.      * @param  Int              Ã¤µµÂüÁ¶ºñÀ²
  599.      * @param  Boolean      ºü¸¥ ·£µå¸µ»ç¿ë¿©ºÎ
  600.      * @return  resource    BufferedImage
  601.     */
  602.     function effectHSB($img$hue_rate 0$sat_rate 100$bri_rate 100$use_speed false){
  603.         $sat_rate $sat_rate 100;
  604.         $bri_rate $bri_rate 100;
  605.         if ($sat_rate == && $hue_rate == && $bri_rate == 0return $img;
  606.         $float_sat $sat_rate/100;
  607.         $float_bri $bri_rate/100;
  608.         
  609.         if ($use_speed{
  610.             $img $this->true2PaletteColor($img,256);
  611.             $color_len imagecolorstotal($img);
  612.             for($i ;  $i $color_len$i++{
  613.                 $rgb imagecolorsforindex($img$i);
  614.                 list($hue,$sat,$bri$this->rgb2hsv($rgb[red],$rgb[green],$rgb[blue]);
  615.                 list($nred,$ngreen,$nblue$this->hsv2rgb($hue $hue_rate,$sat $sat*$float_sat,$bri $bri*$float_bri);
  616.                 imagecolorset ($img$i$nred$ngreen$nblue);
  617.             }
  618.             $img $this->palette2TrueColor($img);
  619.         else {
  620.             $imagex imagesx($img);
  621.             $imagey imagesy($img);
  622.             for ($x 0$x $imagex$x++{
  623.                 for ($y 0$y $imagey$y++{
  624.                     $rgb imagecolorat($img$x$y);
  625.                     $red ($rgb >> 16255;
  626.                     $green ($rgb >> 8255;
  627.                     $blue $rgb 255;
  628.                     list($hue,$sat,$bri$this->rgb2hsv($red,$green,$blue);
  629.                     list($nred,$ngreen,$nblue$this->hsv2rgb($hue $hue_rate,$sat $sat*$float_sat,$bri $bri*$float_bri);
  630.                     $newcol imagecolorallocate($img$nred,$ngreen,$nblue);
  631.                     imagesetpixel($img$x$y$newcol);
  632.                 }
  633.             }
  634.         }
  635.         return $img;
  636.     }
  637.  
  638.     /**
  639.      * ºí·¯ È¿°úÁÖ±â
  640.      *
  641.      * @param  resource      ´ë»ó À̹ÌÁö
  642.      * @param  Int                 ÂüÁ¶ºñÀ²
  643.      * @return  resource    BufferedImage
  644.     */
  645.     function effectBlur($img$rate){
  646.         $rate $rate 10;
  647.         if ($rate == 0return $img;
  648.         if (    $rate 0{
  649.             $this->filterSharpen($img$rate);
  650.             return $img;
  651.         else {
  652.             if ($this->checkFun("imagefilter")) {
  653.                 while($rate 0{
  654.                     imagefilter($imgIMG_FILTER_GAUSSIAN_BLUR);
  655.                     $rate++;
  656.                 
  657.             else {
  658.                 while($rate 0{
  659.                     $this->filterBlur($img1);
  660.                     $rate++;
  661.                 }
  662.             }
  663.             return $img;
  664.         }            
  665.     }
  666.  
  667.     /**
  668.      * »þÆÝ È¿°úÁÖ±â
  669.      *
  670.      * @param  resource      ´ë»ó À̹ÌÁö
  671.      * @param  Int                 ÂüÁ¶ºñÀ²
  672.      * @return  resource    BufferedImage
  673.     */
  674.     function effectSharpen($img$rate){
  675.         if ($rate == 0return $img;
  676.         if ($this->checkFun("imagefilter")) {
  677.             $rate--;
  678.             imagefilter($imgIMG_FILTER_MEAN_REMOVAL);
  679.             return $this->effectSharpen($img$rate);
  680.         else {
  681.             $this->filterSharpen($img$rate);
  682.             return $img;
  683.         }
  684.     }
  685.  
  686.     /**
  687.      *  ±×·¹ÀÌ È¿°úÁÖ±â
  688.      *
  689.      * @param  resource  ´ë»ó À̹ÌÁö
  690.      * @return  resource    BufferedImage
  691.     */
  692.     function effectGray($img){
  693.         if ($this->checkFun("imagefilter")) {
  694.             imagefilter($imgIMG_FILTER_GRAYSCALE);
  695.             return $img;
  696.         else {
  697.             $this->filterGray($img);
  698.             return $img;
  699.         }
  700.     }
  701.  
  702.     /**
  703.      * ³×°¡Æ¼ºê È¿°úÁÖ±â
  704.      *
  705.      * @param  resource  ´ë»ó À̹ÌÁö
  706.      * @return  resource    BufferedImage
  707.     */
  708.     function effectReverse($img){
  709.         if ($this->checkFun("imagefilter")) {
  710.             imagefilter($imgIMG_FILTER_NEGATE);
  711.             return $img;
  712.         else {
  713.             $this->filterReverse($img);
  714.             return $img;
  715.         }
  716.     }
  717.  
  718.     /**
  719.      * ¹à±âÁ¶Á¤ È¿°úÁÖ±â
  720.      *
  721.      * @param  resource  ´ë»ó À̹ÌÁö
  722.      * @param  Int  ´ë»ó ¹à±â(±âº» 100, 100 ÀÌÇÏ : ¾îµÓ°Ô, 100 ÀÌ»ó : ¹à°Ô)
  723.      * @return  resource    BufferedImage
  724.     */
  725.      function effectBrighten($img$bright){
  726.         $bright $bright 100;
  727.         if ($bright == 0)
  728.             return $img;
  729.         if ($this->checkFun("imagefilter")) {
  730.             imagefilter($imgIMG_FILTER_BRIGHTNESSmax(-255,min($bright255)));
  731.             return $img;
  732.         else {
  733.             $this->filterBrighten($img$bright);
  734.             return $img;
  735.         }
  736.     }
  737.  
  738.     /**
  739.      *  ÄÁÆ®¶ó½ºÅÍ È¿°úÁÖ±â
  740.      *
  741.      * @param  resource  ´ë»ó À̹ÌÁö
  742.      * @param  Int  ´ë»ó ´ëºñ(±âº» 100, 100 ÀÌÇÏ : °­ÇϰÔ, 100 ÀÌ»ó : ¾àÇϰÔ)
  743.      * @return  resource    BufferedImage
  744.     */
  745.     function effectContrast($img$cont){
  746.         $cont $cont 100;
  747.         if ($cont == 0)
  748.             return $img;
  749.         if ($this->checkFun("imagefilter")) {
  750.             imagefilter($imgIMG_FILTER_CONTRASTmax(-100,min($cont/2100)));
  751.             return $img;
  752.         else {
  753.             $this->filterContrast($img$cont);
  754.             return $img;
  755.         }
  756.     }
  757.  
  758.     /**
  759.      *  ¾ÈÀü»ö»ó °¡Á®¿À±â(0-255)
  760.      *
  761.      * @param  Int  ´ë»ó»ö»ó
  762.      * @return  Int    ¾ÈÀü»ö»ó
  763.     */
  764.     function getSafeColor($rgb{
  765.         return max(0min(255$rgb));
  766.     }
  767.  
  768.     /**
  769.      *  RGB °ªÀ» int ·Î º¯È¯
  770.      *
  771.      * @param  String  RGB °ª
  772.      * @return  Array    (Àû»ö, ±×¸°, ºí·ç)
  773.     */
  774.     function hex2Int($hexcolor){
  775.         $hex_r $hex_g $hex_b "";
  776.         switch(strlen($hexcolor)) {
  777.             case :
  778.                 $hex_r substr($hexcolor,0,2);    
  779.                 $hex_g substr($hexcolor,2,2);    
  780.                 $hex_b substr($hexcolor,4,2);    
  781.                 break;
  782.             case :
  783.                 $hex_r substr($hexcolor,1,2);    
  784.                 $hex_g substr($hexcolor,3,2);    
  785.                 $hex_b substr($hexcolor,5,2);    
  786.                 break;
  787.             default :
  788.                 $hex_r "FF";
  789.                 $hex_g "FF";
  790.                 $hex_b "FF";
  791.                 break;
  792.         
  793.         $rgb Array($this->hex2Dec($hex_r),$this->hex2Dec($hex_g),$this->hex2Dec($hex_b));
  794.         return $rgb;
  795.     }
  796.  
  797.     /**
  798.      *  RGB °ªÀ» HSV ·Î º¯È¯
  799.      *
  800.      * @param  Int  red °ª
  801.      * @param  Int  green °ª
  802.      * @param  Int  blue °ª
  803.      * @return  Array    (hue, saturation, brightness)
  804.     */
  805.     function rgb2hsv($r$g$b{
  806.         $r max(0min($r255));
  807.         $g max(0min($g255));
  808.         $b max(0min($b255));
  809.         if (    $this->base_rgb2hue[$r][$g][$b!= null)
  810.             return $this->base_rgb2hue[$r][$g][$b];
  811.         $max=max($r,$g,$b);
  812.         $delta=$max-min($r,$g,$b);
  813.         if ($delta == 0$H 0;
  814.         else $S$delta/$max*100;
  815.         if($S == 0$H=0;
  816.         else if($max!=0
  817.             $S=$delta/$max*100;
  818.             if($r==$max
  819.                 $H=($g-$b)/$delta
  820.             else if($g==$max
  821.                 $H=2+($b-$r)/$delta
  822.             else if($b==$max
  823.                 $H=4+($r-$g)/$delta;
  824.             $H=min($H*60,360)
  825.             if($H<0$H+=360;
  826.         }
  827.         return $this->base_rgb2hue[$r][$g][$bArray($H?$H:0,$S?$S:0,($max/255)*100);
  828.     }
  829.     
  830.     /**
  831.      *  HSV °ªÀ» RGB ·Î º¯È¯
  832.      *
  833.      * @param  Int  hue °ª
  834.      * @param  Int  saturation °ª
  835.      * @param  Int  brightness °ª
  836.      * @return  Array    (red, green, blue)
  837.     */
  838.     function hsv2rgb($h$s$v{
  839.         $h round($h 360);
  840.         if ($h 0)
  841.             $h 360 $h;
  842.         $s round(max(0min($s100)));
  843.         $v round(max(0min($v100)));
  844.         if (    $this->base_hue2rgb[$h][$s][$v!= null)
  845.             return $this->base_hue2rgb[$h][$s][$v];
  846.  
  847.         $S=$s/100;
  848.         $V=$v/100;
  849.         $H=$h/360;
  850.         if($S>0
  851.             if($H>=1$H=0;
  852.             $H=6*$H$F=$H-floor($H);
  853.             $A=round(255*$V*(1.0-$S));
  854.             $B=round(255*$V*(1.0-($S*$F)));
  855.             $C=round(255*$V*(1.0-($S*(1.0-$F))));
  856.             $V=round(255*$V)
  857.             switch(floor($H)) {
  858.                 case 0$R=$V$G=$C$B=$Abreak;
  859.                 case 1$R=$B$G=$V$B=$Abreak;
  860.                 case 2$R=$A$G=$V$B=$Cbreak;
  861.                 case 3$R=$A$G=$B$B=$Vbreak;
  862.                 case 4$R=$C$G=$A$B=$Vbreak;
  863.                 case 5$R=$V$G=$A$B=$Bbreak;
  864.             }
  865.             return $this->base_hue2rgb[$h][$s][$vArray($R?$R:0,$G?$G:0,$B?$B:0);
  866.         else {
  867.             $V=round($V*255);
  868.             return $this->base_hue2rgb[$h][$s][$vArray($V,$V,$V);
  869.         }
  870.     }    
  871.  
  872.     /**
  873.      *  RGB °ªÀ» Color ·Î º¯È¯
  874.      *
  875.      * @param  resource  ´ë»óÀ̹ÌÁö
  876.      * @param  String  RGB °ª
  877.      * @param  Int  ¾ËÆÄ°ª
  878.      * @return  Int    Color
  879.     */
  880.     function getColor($img$hexcolor$alpha 0){
  881.         $rgb $this->hex2Int($hexcolor);
  882.         if ($alpha == 0)
  883.             return imagecolorallocate($img$rgb[0]$rgb[1]$rgb[2]);
  884.         else
  885.             return imagecolorallocatealpha($img$rgb[0]$rgb[1]$rgb[2]min($alpha,127));
  886.     }
  887.  
  888.     /**
  889.      *  Color À» ÀÎÅØ½º Ä®¶ó·Î º¯È¯
  890.      *
  891.      * @param  resource  ´ë»óÀ̹ÌÁö
  892.      * @param  Int  Ä®¶ó°ª
  893.      * @return  Int    Color
  894.     */
  895.     function color2int($img$intcolor{
  896.         return imagecolorsforindex($img$intcolor);
  897.     }
  898.    
  899.     /**
  900.      *  HEX °ªÀ» 10Áø¼ö·Î º¯È¯
  901.      *
  902.      * @param  String ´ë»ó hex °ª
  903.      * @return  Int    10Áø¼ö
  904.     */
  905.     function hex2Dec($s{
  906.         return hexdec($s);
  907.     }
  908.  
  909.     /**
  910.      *  ÁÖ¾îÁø À̹ÌÁö¸¦ ±âº»À̹ÌÁö¿¡ º¹»ç
  911.      *
  912.      * @param  resource º¹»çÇÒ À̹ÌÁö
  913.      * @param  Int ´ë»ó X ÁÂÇ¥
  914.      * @param  Int ´ë»ó Y ÁÂÇ¥
  915.      * @param  Int º¹»çÇÒÀ̹ÌÁöÀÇ X ÁÂÇ¥
  916.      * @param  Int º¹»çÇÒÀ̹ÌÁöÀÇ Y ÁÂÇ¥
  917.      * @param  Int º¹»çÇÒÀ̹ÌÁöÀÇ °¡·ÎÅ©±â
  918.      * @param  Int º¹»çÇÒÀ̹ÌÁöÀÇ ¼¼·ÎÅ©±â
  919.      * @param  Boolean ½º¸¶Æ¼º¹»ç»ç¿ë¿©ºÎ
  920.     */
  921.     function copy($img$x$y$w 0$h 0$sx 0$sy 0$smart_copy false){
  922.         if ($w == || $h == 0{
  923.             $w imagesx($img);
  924.             $h imagesy($img);
  925.         }
  926.         if ($smart_copy{
  927.             $img_w imagesx($this->img);
  928.             $img_h imagesy($this->img);
  929.             if ($x $w $img_w{
  930.                 $sx += ($x $w $img_w);
  931.                 $w -= ($x $w $img_w);
  932.             }
  933.             if ($y $h $img_h{
  934.                 $sy += ($y $h $img_h);
  935.                 $h -= ($y $h $img_h);
  936.             }
  937.         }
  938.         if ($w $h 0)
  939.             imagecopy($this->img$img$x$y$sx$sy$w$h);
  940.     }
  941.  
  942.     /**
  943.      * ±âº»À̹ÌÁö¿¡ ¹®ÀÚ³Ö±â
  944.      *
  945.      * @param  String ³ÖÀ» ¹®ÀÚ
  946.      * @param  Int ´ë»ó X ÁÂÇ¥
  947.      * @param  Int ´ë»ó Y ÁÂÇ¥
  948.      * @param  String ±Û¾¾ »ö»ó
  949.     */
  950.     function text($text$x$y$hexcolor "#464646"){
  951.         $black $this -> getColor($this->img$hexcolor);
  952.         imagestring($this->img3$x$y$text$black);
  953.     }
  954.  
  955.     /**
  956.      *  À̹ÌÁö Å©±âÁ¶Á¤
  957.      *
  958.      * @param  resource ´ë»óÀ̹ÌÁö
  959.      * @param  Int ´ë»ó °¡·ÎÅ©±â
  960.      * @param  Int ´ë»ó ¼¼·ÎÅ©±â
  961.      * @return  resource    BufferedImage
  962.     */
  963.     function resize($img$w$h 0){
  964.         if ($h <= 0{
  965.             $ow imagesx($img);
  966.             $oh imagesy($img);
  967.             $h round($oh ($w/$ow));
  968.         }
  969.         $newimg $this->getImg($w,$h);
  970.         if ($this->checkFun("imagecopyresampled")) {
  971.             $newimg $this->getImg($w,$h);
  972.             ImageCopyResampled($newimg$img0000$w$himagesx($img)imagesy($img));
  973.         }
  974.         return $newimg;
  975.     }
  976.  
  977.     /**
  978.      *  À̹ÌÁö Å©±âÁ¶Á¤(ÀåÃà ´ë»ó Á¶Á¤)
  979.      *
  980.      * @param  resource ´ë»óÀ̹ÌÁö
  981.      * @param  Int ÀåÃà ÃÖ´ëÅ©±â
  982.      * @return  resource    BufferedImage
  983.     */
  984.     function resizeMax($img$max_size){
  985.         $ow imagesx($img);
  986.         $oh imagesy($img);
  987.         if ($ow $max_size || $oh $max_size{
  988.             $rate $ow/$oh;
  989.             if ($rate 1{
  990.                 $ow $max_size;
  991.                 $oh round($max_size $rate);
  992.             else {
  993.                 $ow round($max_size $rate);
  994.                 $oh $max_size;
  995.             }    
  996.             $img $this->resize($img$ow$oh);
  997.         }
  998.         return $img;
  999.     }    
  1000.  
  1001.     /**
  1002.      *  À̹ÌÁö ¹Ýº¹
  1003.      *
  1004.      * @param  resource ´ë»óÀ̹ÌÁö
  1005.      * @param  Int ´ë»ó°¡·ÎÅ©±â
  1006.      * @param  Int ´ë»ó¼¼·ÎÅ©±â
  1007.      * @return  resource    BufferedImage
  1008.     */
  1009.     function fill($img$w$h){
  1010.         $ow imagesx($img);
  1011.         $oh imagesy($img);
  1012.         $newimg $this->getImg($w,$h);
  1013.         $x $y 0;
  1014.         $x 0;
  1015.         do {
  1016.             $y 0;
  1017.             do {
  1018.                 imagecopy($newimg$img$x$y 00$ow$oh);
  1019.                 $y += $oh;
  1020.             while($y <= $h $oh );
  1021.             $x += $ow;
  1022.         while($x <= $w $ow);
  1023.         
  1024.         return $newimg;
  1025.     }
  1026.  
  1027.     /**
  1028.      *  À̹ÌÁö¿¡¼­ Æ¯Á¤¿µ¿ª°¡Á®¿À±â
  1029.      *
  1030.      * @param  resource ´ë»óÀ̹ÌÁö
  1031.      * @param  Int ´ë»óÀ§Ä¡(1:Áß°£»ó, 2 : ÁÂÁß°£, 3 : ÇÏÁß°£, 4: ÁÂÁß°£,0 : Áß°£Áß°£)
  1032.      * @param  Int ´ë»ó°¡·ÎÅ©±â
  1033.      * @param  Int ´ë»ó¼¼·ÎÅ©±â
  1034.      * @return  resource    BufferedImage
  1035.     */
  1036.     function getFilled($img$pos$w$h){
  1037.         $fw imagesx($img);
  1038.         $fh imagesy($img);
  1039.         $newimg $this->getImg($w,$h);
  1040.         switch($pos{
  1041.             case 
  1042.                 $newimg $this->getSubimage($img,4,0,$fw-8,4);
  1043.                 break;
  1044.             case 
  1045.                 $newimg $this->getSubimage($img,$fw-4,4,4,$fh-8);
  1046.                 break;
  1047.             case 
  1048.                 $newimg $this->getSubimage($img,4,$fh-4,$fw-8,4);
  1049.                 break;
  1050.             case 
  1051.                 $newimg $this->getSubimage($img,0,4,4,$fh-8);
  1052.                 break;
  1053.             case 
  1054.                 $newimg $this->getSubimage($img,4,4,$fw-8,$fh-8);
  1055.                 break;
  1056.         }
  1057.         return $this->fill($newimg$w,$h);
  1058.     }
  1059.  
  1060.     /**
  1061.      *  ÇÁ·¹ÀΠÀ̹ÌÁö Àоî¿À±â
  1062.      *
  1063.      * @param  String ÇÁ·¹ÀÓÀ̸§
  1064.      * @param  String ¶óÀλö»ó
  1065.      * @param  String ¹è°æ»ö»ó
  1066.      * @return  resource    BufferedImage
  1067.     */
  1068.     function loadFrame($frmName$linecolor$bgcolor){
  1069.         $compiled_filename "imgstyle/compiled/" strtolower(rainUtil::replace("#"""$bgcolor "_" $linecolor "_" $frmName "_main_php.png"));
  1070.         if (file_exists($this->getBaseRoot($compiled_filename)) {    
  1071.             return $this->load($compiled_filename);
  1072.         else {
  1073.             $frmimg $this->load("imgstyle/" $frmName "_main.png");
  1074.             $fw imagesx($frmimg);
  1075.             $fh imagesy($frmimg);
  1076.             $newimg $this->getImg($fw,$fh);
  1077.             $bg $this->getColor($newimg,$bgcolor);
  1078.             $line $this->getColor($newimg,$linecolor;
  1079.             $trance $this->getColor($newimg,"#005283");
  1080.             imagecolortransparent($newimg$trance);
  1081.             for($x 0$x $fw$x++{
  1082.                 for($y 0$y $fh$y++{
  1083.                     $pixcolor imagecolorat($frmimg,$x,$y);
  1084.                     if ($pixcolor == 255)
  1085.                         imagesetpixel($newimg$x$y$trance);
  1086.                     else if ($pixcolor == 0)
  1087.                         imagesetpixel($newimg$x$y$line);
  1088.                     else if ($pixcolor == 16777215)
  1089.                         imagesetpixel($newimg$x$y$bg);
  1090.                 }
  1091.             }
  1092.             imagepng($newimg$this->getBaseRoot($compiled_filename);
  1093.             return $newimg;
  1094.         }
  1095.     }
  1096.  
  1097.     /**
  1098.      *  ÇöÀçÀÇ À̹ÌÁö¿¡ ÇÁ·¹ÀÓ ³Ö±â
  1099.      *
  1100.      * @param  String ÇÁ·¹ÀÓÀ̸§
  1101.      * @param  String ¶óÀλö»ó
  1102.      * @param  String ¹è°æ»ö»ó
  1103.     */
  1104.     function setFrame($frmName$lineColor "#464646"$bgColor "#FFFFFF"){
  1105.         $ow imagesx($this->img);
  1106.         $oh imagesy($this->img);
  1107.         $frmimg $this->loadFrame($frmName$lineColor$bgColor);
  1108.         $fw imagesx($frmimg);
  1109.         $fh imagesy($frmimg);
  1110.         $this->copy($frmimg0,04,40,0);
  1111.         $this->copy($frmimg$ow-4,0,4,4,$fw-4,0);
  1112.         $this->copy($frmimg0,$oh-4,4,4,0,$fh-4);
  1113.         $this->copy($frmimg$ow-4,$oh-4,4,4,$fw-4,$fh-4);
  1114.         $this->copy($this->getFilled($frmimg,1$ow-84),4,0);
  1115.         $this->copy($this->getFilled($frmimg,24$oh-8)$ow-4,4);
  1116.         $this->copy($this->getFilled($frmimg,3$ow-84)4,$oh-4);
  1117.         $this->copy($this->getFilled($frmimg,44$oh-8)0,4);
  1118.         $this->copy($this->getFilled($frmimg,0$ow-8$oh-8)4,4);
  1119.         $trance $this->getColor($this->img,"#005283");
  1120.         imagecolortransparent($this->img$trance);
  1121.     }
  1122.  
  1123.     /**
  1124.      *  À̹ÌÁö ¹Ýº¹ º¹»ç
  1125.      *
  1126.      * @param  resource ´ë»óÀ̹ÌÁö
  1127.      * @param  Int ´ë»ó X ÁÂÇ¥
  1128.      * @param  Int ´ë»ó Y ÁÂÇ¥
  1129.      * @param  Int ´ë»ó°¡·ÎÅ©±â
  1130.      * @param  Int ´ë»ó¼¼·ÎÅ©±â
  1131.      * @param  Int ¿øº» X ÁÂÇ¥
  1132.      * @param  Int ¿øº» Y ÁÂÇ¥
  1133.      * @param  Int ¿øº»°¡·ÎÅ©±â
  1134.      * @param  Int ¿øº»¼¼·ÎÅ©±â
  1135.      * @param  Boolean °­Á¦´Ã¸®±â »ç¿ë¿©ºÎ
  1136.      * @return  resource    BufferedImage
  1137.     */
  1138.     function fillCopy($img$ox$oy$ow$oh$sx$sy$sw$sh$stretch_mode 0){
  1139.         if ($stretch_mode == 0{
  1140.             @imagecopyresized($this->img$img$sx$sy$ox$oy$sw$sh$ow$oh);
  1141.         else {
  1142.             $ow ceil($ow);
  1143.             $oh ceil($oh);
  1144.             if ($ow == || $oh == || $sw == || $sh == 0)
  1145.                 return ;
  1146.             $x $y $tmp_width $tmp_height 0;
  1147.             do {
  1148.                 $y 0;
  1149.                 $tmp_height 0;
  1150.                 do {
  1151.                     if ($y <= $sh || $x <= $sw{
  1152.                         $tmp_height +=  $ow;
  1153.                         $tg_width $ow;
  1154.                         $tg_height $oh;
  1155.                         if ($tg_width && $tg_height 0)
  1156.                             $this->copy($imground($sx $x)ceil($sy $y)round($tg_width)round($tg_heightround($ox)round($oy)round($tg_width)round($tg_height));
  1157.                     }                
  1158.                     $y += $oh;
  1159.                 while($y $sh);
  1160.                 $x += $ow;
  1161.             while($x $sw);
  1162.         }
  1163.     }
  1164.  
  1165.     /**
  1166.      *  À̹ÌÁö¿¡ ¾ËÆÄ È¿°ú ÁÖ±â
  1167.      *
  1168.      * @param  String ¹èÀ̹ÌÁö¸í
  1169.      * @param  String ¾ËÆÄ È¿°ú ¹æÇâ[S = 3¹æÇâ, SL= ÁÂÃøÇÏ´Ü, SR = ¿ìÃøÇÏ´Ü, SY = ÇÏ´Ü]
  1170.      * @param  String ¾ËÆÄ »ö»ó
  1171.      * @param  Int ±âº» ³ôÀÌ
  1172.      * @return  resource    BufferedImage
  1173.     */
  1174.     function getColorAlpha($bg_img$alpha_img$bgcolor$max_height 0){
  1175.         $bgimg $this -> load($bg_img);
  1176.         if ($max_height && imagesy($bgimg$max_height)
  1177.             $bgimg =     $this->img = $this->getSubimage($bgimg00imagesx($bgimg),$max_height);
  1178.         $alphaimg null;
  1179.         switch($alpha_img{
  1180.             case 'S' :
  1181.                 $alphaimg $this -> load('colorskin/bg_alpha.png');
  1182.                 break;
  1183.             case 'SL' :
  1184.                 $alphaimg $this -> load('colorskin/bg_alpha_xl.png');
  1185.                 break;
  1186.             case 'SR' :
  1187.                 $alphaimg $this -> load('colorskin/bg_alpha_xr.png');
  1188.                 break;
  1189.             case 'SY' :
  1190.                 $alphaimg $this -> load('colorskin/bg_alpha_y.png');
  1191.                 break;
  1192.         }
  1193.         if (    $alphaimg != null{
  1194.             imagealphablending($alphaimgfalse);
  1195.             $alpha_w imagesx($alphaimg);
  1196.             $alpha_h imagesy($alphaimg);
  1197.             $rgb $this->hex2Int($bgcolor);
  1198.             $alpha_index Array();
  1199.             for($x 0$x <= 127$x++
  1200.                 $alpha_index[$ximagecolorallocatealpha($alphaimg$rgb[0]$rgb[1]$rgb[2]$x);
  1201.             for($x $x $alpha_w $x++{
  1202.                 for($y $y $alpha_h$y++{
  1203.                     $color_index =  imagecolorat($alphaimg$x$y);
  1204.                     $alpha_color imagecolorsforindex($alphaimg$color_index);
  1205.                     imagesetpixel($alphaimg$x$y$alpha_index[$alpha_color[alpha]]);
  1206.                 }
  1207.             }
  1208.             ImageCopyResampled($bgimg$alphaimg0000imagesx($bgimg)imagesy($bgimg)imagesx($alphaimg)imagesy($alphaimg));
  1209.         }
  1210.         return $bgimg;
  1211.     }
  1212.     
  1213.     /**
  1214.      *  »ö»ó ½ºÅ² °¡Á®¿À±â
  1215.      *
  1216.      * @param  String ½ºÅ²À̸§
  1217.      * @param  Array »ö»ó¸ÅÄ¡
  1218.      * @param  Int °¡·ÎÆø
  1219.      * @param  Int ¼¼·Î³ôÀÌ
  1220.      * @param  Int ±âº» ³ôÀÌ
  1221.      * @param  String ÀÛ¾÷¿µ¿ª Æúµå¸í
  1222.      * @param  String ¹è°æÀ̹ÌÁö
  1223.      * @param  Int         Åõ¸íµµ
  1224.      * @return  resource    BufferedImage
  1225.     */
  1226.     function getColorSkin($skin_name$color_match Array()$width 0$height 0$base_dir ''$bg_img ''$bg_rate 0){
  1227.         $skininfo @parse_ini_file($this->getBaseRoot().'colorskin/'.$skin_name.'.ini');
  1228.         $filename ($skininfo['filename'== '')$skin_name.'.png' $skininfo['filename'];
  1229.         $frm_img $this->load('colorskin/'.$filename);
  1230.         $tar_color Array();
  1231.         $src_color Array();
  1232.         $prokey array("linecolor""bgcolor","titlecolor","transcolor");
  1233.         $bg_color '';
  1234.         $have_trans false;
  1235.         foreach($prokey as $key{
  1236.             if ($skininfo[$key!= ''{
  1237.                 $skin_color $skininfo[$key];
  1238.                 $rgb $this->hex2Int($skin_color);
  1239.                 if ($color_match[$key!= ''{
  1240.                     $val strtoupper($color_match[$key]);
  1241.                     $tar_color[=      Array 'red' => $rgb[0],'green' => $rgb[1],'blue' => $rgb[2,'alpha' => );
  1242.                     if ($key == 'bgcolor'
  1243.                         $bg_color $val;
  1244.                     if (strtoupper($val== 'TRANSPARENT' || $val == '#005283'{
  1245.                         $src_color[Array 'red' => 0,'green' => 0,'blue' => ,'alpha' => 127);
  1246.                         $have_trans true;
  1247.                     else {
  1248.                         $rgb $this->hex2Int($val);
  1249.                         $src_color[Array 'red' => $rgb[0],'green' => $rgb[1],'blue' => $rgb[2,'alpha' => );
  1250.                     }
  1251.                 }
  1252.             }
  1253.         }
  1254.         $lastcolor_is_transparent (!$skininfo['nottranscolor']true false;
  1255.         $trans_color_idx = -1;
  1256.         if ($have_trans || $lastcolor_is_transparent{
  1257.             $trans_color_idx imagecolortransparent($frm_img);
  1258.             if ($trans_color_idx == -1{
  1259.                 $trans_color $this -> getColor($frm_img'#005282');
  1260.                 $trans_color_idx imagecolortransparent($frm_img$trans_color);
  1261.             }  else {
  1262.                 $trans_color $this -> hex2Int('#005282');
  1263.                 imagecolorset($frm_img$trans_color_idx$trans_color[0],$trans_color[1],$trans_color[2]);
  1264.             }
  1265.             $trans_color imagecolorsforindex($frm_img$trans_color_idx);
  1266.         }
  1267.         if (!imageistruecolor($frm_img)) {
  1268.             $len imagecolorstotal($frm_img);
  1269.             for ($i $i $len$i++{
  1270.                 $color imagecolorsforindex($frm_img$i);
  1271.                 if ($trans_color_idx == $i{
  1272.                     imagecolortransparent($frm_img$i);
  1273.                 else if (($key array_search($color$tar_color)) !== false{
  1274.                     if ($src_color[$key!= $color || $src_color[$key]['alpha'== 127{
  1275.                         if ($src_color[$key]['alpha'== 127{
  1276.                             imagecolorset($frm_img$i$trans_color['red'],$trans_color['green'],$trans_color['blue']);
  1277.                         else {
  1278.                             imagecolorset($frm_img$i$src_color[$key]['red'],$src_color[$key]['green'],$src_color[$key]['blue']);
  1279.                         }
  1280.                     }
  1281.                 }
  1282.             }
  1283.         }
  1284.         if ($skininfo['img_mask'!= ''{
  1285.             $tmp_img $this->getImg(imagesx($frm_img)imagesy($frm_img),true);
  1286.             imagecopymerge($tmp_img,$frm_img0,0,0,0,imagesx($frm_img),imagesy($frm_img),100);
  1287.             $frm_img $tmp_img;
  1288.             $mask_img $this->load('colorskin/'.$skininfo['img_mask']);
  1289.             ImageCopyResampled($frm_img$mask_img0000imagesx($frm_img),imagesy($frm_img)imagesx($mask_img),imagesy($mask_img));
  1290. //            imagecopy($frm_img, $mask_img,0,0,0,0,imagesx($mask_img),imagesy($mask_img));
  1291.         }
  1292.                 
  1293.         $prokey array("stretch_width""stretch_height","pic_drawpt","extraspace");
  1294.         foreach($prokey as $key
  1295.             list($skininfo[$key.'_0']$skininfo[$key.'_1']$skininfo[$key.'_2']explode(' ',$skininfo[$key]);
  1296.         $frm_width imagesx($frm_img);
  1297.         $frm_height imagesy($frm_img);
  1298.         
  1299.         $img_width $width $skininfo['extraspace_0'];
  1300.         $img_height $height $skininfo['extraspace_1'];
  1301.         
  1302.         if ($img_width $frm_width$img_width $frm_width;
  1303.         if ($img_height $frm_height$img_height $frm_height;
  1304.         
  1305.         if ($frm_width >= $img_width && $frm_height >= $img_height
  1306.             $this->img = $this->getSubimage($frm_img00imagesx($frm_img),imagesy($frm_img)true);
  1307.         else {
  1308.             $this->img = $this->getImg($img_width$frm_height,true);
  1309.             $frm_x $frm_y 0;
  1310.             $img_x $img_y 0;
  1311.             if ($frm_width >= $img_width
  1312.                 $this->img = $frm_img;
  1313. //                $this->img = $this->getSubimage($frm_img, 0, 0, imagesx($frm_img),imagesy($frm_img), true);
  1314.             else {
  1315.                 $frm_w $skininfo['stretch_width_0'];
  1316.                 $img_h $frm_h $frm_height;
  1317.                 $this->copy($frm_img$img_x$img_y$frm_w$frm_h$frm_x$frm_y);
  1318.                 $frm_w $skininfo['stretch_width_1'];
  1319.                 $frm_x $skininfo['stretch_width_0'];
  1320.                 $img_w $img_width ($frm_width $skininfo['stretch_width_1']);
  1321.                 $img_x $skininfo['stretch_width_0'];
  1322.                 $this->fillCopy($frm_img$frm_x$frm_y$frm_w,$frm_h$img_x$img_y$img_w$img_h$skininfo['stretch_width_2']);
  1323.                 $img_x += $img_w;
  1324.                 $frm_x += $frm_w;
  1325.                 $frm_w $img_w =$frm_width ($skininfo['stretch_width_0'$skininfo['stretch_width_1']);
  1326.                 $this->copy($frm_img$img_x$img_y$frm_w$frm_h$frm_x$frm_y);
  1327.             }
  1328.             if ($frm_height >= $img_height{
  1329.                 $img_height $frm_height;
  1330.             else {
  1331.                 $frm_img $this->img;
  1332.                 $this->img = $this->getImg($img_width$img_height,true);
  1333.                 $frm_x $frm_y 0;
  1334.                 $img_x $img_y 0;
  1335.                 $frm_h $skininfo['stretch_height_0'];
  1336.                 $img_w $frm_w $img_width;
  1337.                 $this->copy($frm_img$img_x$img_y$img_width$frm_h$frm_x$frm_y);
  1338.                 $frm_h $skininfo['stretch_height_1'];
  1339.                 $frm_y $skininfo['stretch_height_0'];
  1340.                 $img_h $img_height ($frm_height $skininfo['stretch_height_1']);
  1341.                 $img_y $skininfo['stretch_height_0'];
  1342.                 $this->fillCopy($frm_img$frm_x$frm_y$img_width,$frm_h$img_x$img_y$img_width$img_h$skininfo['stretch_height_2']);
  1343.                 $img_y += $img_h;
  1344.                 $frm_y += $frm_h;
  1345.                 $frm_h $img_h =$frm_height ($skininfo['stretch_height_0'$skininfo['stretch_height_1']);
  1346.                 $this->copy($frm_img$img_x$img_y$img_width$frm_h$frm_x$frm_y);
  1347.             }
  1348.         }
  1349.         if ($bg_rate && $bg_img != '' && $bg_color != ''{
  1350.             $bgimg $this->getColorMask($this->load($bg_img)$this->img$bg_color);
  1351.             imagecopymerge ($this->img$bgimg0000$img_width$img_height$bg_rate);
  1352.         }
  1353.  
  1354.         if ($base_dir != '' && rainUtil::checkDir($this->getBaseRoot()$base_dir.'/junk.ini')) {    
  1355.             for($i 0$i 35$i++{
  1356.                 if ($skininfo['img'.$i!= ''{
  1357.                     list($x,$y$w$h,$img_nameexplode(' ',$skininfo['img'.$i]);
  1358.                     $w ($w == 0$img_width:$w;
  1359.                     $h ($h == 0$img_height:$h;
  1360.                     $x ($x 0$img_width+$x:$x;
  1361.                     $y ($y 0$img_height+$y:$y;
  1362.                     $tmp $this->getSubimage($this->img$x$y$w,$htrue);
  1363.                     $tmp2 imagecreate($w$h);
  1364.                     $white $this -> getColor($tmp2'#005282');
  1365.                     imagefilledrectangle($tmp200100100$white);
  1366.                     imagecolortransparent($tmp2$white);
  1367.                     imagecopymerge($tmp2$tmp,0,0,0,0,$w,$h,100);
  1368.                     imagegif($tmp2$this->getBaseRoot($base_dir.'/'.$img_name);
  1369.                     imagedestroy($tmp);
  1370.                     imagedestroy($tmp2);
  1371.                 }
  1372.             }
  1373.         }
  1374.         return $this->img;
  1375.     }
  1376.  
  1377.     /**
  1378.      *  »ö»ó ¸¶½ºÅ© °¡Á®¿À±â
  1379.      *
  1380.      * @param  resource ¼Ò½º À̹ÌÁö
  1381.      * @param  resource ¸¶½ºÅ© À̹ÌÁö
  1382.      * @param  String            ¸¶½ºÅ© »ö»ó
  1383.      * @return  resource    BufferedImage
  1384.     */
  1385.     function getColorMask($source_img$mask_img$mask_color){
  1386.         $color_rate 100;
  1387.         $tmp_color '#ff0000'// #1f4e17;
  1388.         $img_width imagesx($mask_img);
  1389.         $img_height imagesy($mask_img);
  1390.         $tmp_img $this->getImg($img_width$img_height);
  1391.         $white $this -> getColor($tmp_img$tmp_color);
  1392.         imagefilledrectangle($tmp_img00$img_width$img_height$white);
  1393.         imagecolortransparent($tmp_img$white);
  1394.         imagecopy($tmp_img$mask_img0,0,0,0,$img_width$img_height);
  1395.         $mask_img $this->true2PaletteColor($tmp_img,256);
  1396.         $tmp_rgb $this->hex2Int($tmp_color);
  1397.         $rgb $this->hex2Int($mask_color);
  1398.         $len imagecolorstotal($mask_img);
  1399.         for ($i 0$i $len$i++{
  1400.             $color imagecolorsforindex($mask_img$i);
  1401.             if (round($color['red']/$color_rate== round($rgb[0]/$color_rate&& round($color['green']/$color_rate== round($rgb[1]/$color_rate&& round($color['blue']/$color_rate== round($rgb[2]/$color_rate))
  1402.                 imagecolortransparent($mask_img$i);
  1403.             else
  1404.                 imagecolorset($mask_img$i$tmp_rgb[0],$tmp_rgb[2],$tmp_rgb[2]);
  1405.         }
  1406.         $tmp_img $this->fill($source_img,$img_width$img_height);
  1407.         $tmp_img $this->effectGray($tmp_img);
  1408.         imagecopy($tmp_img,$mask_img0,0,0,0,$img_width$img_height);
  1409.         imagecolortransparent($tmp_img$white);
  1410.         return $tmp_img;
  1411.     }
  1412.  
  1413.     /**
  1414.      *  ÇÁ·¹ÀÓ Á¤º¸ XML °¡Á®¿À±â
  1415.      * 
  1416.      * @return  String    ÇÁ·¹ÀÓ Á¤º¸ XML
  1417.     */
  1418.     function getSkinXml(){
  1419.         if (!rainUtil::file_exists('skin/skin_editorinfo.xml'|| filemtime($this->getBaseRoot().'skin/skin_editorinfo.xml'filemtime($this->getBaseRoot().'skin/skin_masterinfo.ini')) {
  1420.             $skinmaster new rainProperties($this->getBaseRoot().'skin/skin_masterinfo'true);
  1421.             $xml '';
  1422.             $bgtable $this->load("skin/1320x1320.png");
  1423.             foreach($skinmaster-> propertyNames(as $skin_key{
  1424.                 list($skin_name$skin_seqnexplode(' ',$skinmaster->get($skin_key));
  1425.                 $skin_seqn intval($skin_seqn);
  1426.                 if ($skin_seqn 0{
  1427.                     $skin_no 0;
  1428.                     $reg array();
  1429.                     if  (rainUtil::find("s([0-9]+)"$skin_key&$reg))
  1430.                         $skin_no rainUtil::string2Int($reg[1]);
  1431.                     $fileName "skin/120x120bg.png_K".$skin_no.".png";
  1432.                     if ($this->makeThumb($fileName)) {
  1433.                         $img_name "skin/icon/".$skin_no.".png";
  1434.                         if (rainUtil::file_exists($img_name))
  1435.                             rainUtil::unlink($img_name);
  1436.                         rainUtil::rename($fileName$img_name);
  1437.                         $tmp $this->getSubimage($this->load($img_name),0,0,120,120);
  1438.                         imagepng($tmp$this->getBaseRoot()."skin/icon/icon_".$skin_no.".png");
  1439.                         if ($skin_seqn && $skin_seqn 100{
  1440.                             $x ($skin_seqn 10120 60;
  1441.                             $y floor($skin_seqn/10)*120 60;
  1442.                             imagecopy($bgtable$tmp$x,$y0,0110,110);
  1443.                         }
  1444.                     }
  1445.                     $skininfo new rainProperties($this->getBaseRoot().'skin/'.$skin_nametrue);
  1446.                     $xml .= "<item>\r\n";
  1447.                     $xml .= "\t<name><![CDATA[".$skin_no."]]></name>\r\n";
  1448.                     $xml .= "\t<seqn><![CDATA[".$skin_seqn."]]></seqn>\r\n";
  1449.                     $xml .= "\t<icon><![CDATA[icon_".$skin_no.".png]]></icon>\r\n";
  1450.                     $xml .= "\t<description><![CDATA[".$skininfo->get('title')."]]></description>\r\n";
  1451.                     $xml .= "</item>\r\n";
  1452.                 }
  1453.             }
  1454.             imagepng($bgtable$this->getBaseRoot()."../images/skin_thumbnail.png");
  1455.             if ($handle @fopen($this->getBaseRoot().'skin/skin_editorinfo.xml'"w")) {
  1456.                 fwrite($handle ,$xml);
  1457.                 fclose($handle);
  1458.             }
  1459.             return $xml;
  1460.         else {
  1461.             $file new rainFile($this->getBaseRoot());
  1462.             return $file->fileLoader("skin/skin_editorinfo.xml");
  1463.         }            
  1464.     }
  1465.  
  1466.     /**
  1467.      *  ÇÁ·¹ÀÓ Á¤º¸ °¡Á®¿À±â
  1468.      *
  1469.      * @param  String ÇÁ·¹ÀÓ¸í
  1470.      * @return     Array    ÇÁ·¹ÀÓÁ¤º¸
  1471.     */
  1472.     function loadSkin($frmName){
  1473.         $skininfo Array();
  1474.         if ($masterinfo @parse_ini_file($this->getBaseRoot().'skin/skin_masterinfo.ini')) {
  1475.             list($frmNameexplode(' ',$masterinfo['s'.$frmName]);
  1476.             if ($frmName != ''{
  1477.                 $skininfo @parse_ini_file($this->getBaseRoot().'skin/'.$frmName.'.ini');
  1478.                 if ($skininfo['file'!= '')
  1479.                     $skininfo['skinimg']$frmName.".png";
  1480.                 $prokey array("extraspace","upleft""upmid""upright""ctleft""ctright""btleft""btmid""btright""pic_drawpt");
  1481.                 foreach($prokey as $key
  1482.                     list($skininfo[$key.'_0']$skininfo[$key.'_1']explode(' ',$skininfo[$key]);
  1483.             
  1484.         }
  1485.         return $skininfo;
  1486.     }
  1487.  
  1488.     /**
  1489.      *  À̹ÌÁö¿¡ Text Ãß°¡Çϱâ
  1490.      *
  1491.      * @param  resource ´ë»ó À̹ÌÁö
  1492.      * @param  Array Ãß°¡ÇÒ ¹®ÀÚ Á¤º¸
  1493.      * @param  Int °¡·Î¼¼·Î ¿©¹é
  1494.      * @return  resource    BufferedImage
  1495.     */
  1496.     function addText($src_img$text Array()$padding 5){
  1497.         if (count($text0{
  1498.             $add_height count($text15 $padding *2;
  1499.             $img_width imagesx($src_img);
  1500.             $img_height imagesy($src_img)  $add_height;
  1501.             $img $this->getImg($img_width$img_height);
  1502.             $white $this -> getColor($img'#FFFFFF');
  1503.             $black $this -> getColor($img'#464646');
  1504.             imagefilledrectangle($img00$img_width$img_height$white);
  1505.             $y imagesy($src_img$padding 15;
  1506.             $base_x $img_width $padding;
  1507.             foreach($text as $val{
  1508.                 $val trim($val);
  1509.                 if ($val  != '')
  1510.                     imagestring($img3$base_x strlen($val)*7$y += 15$val$black);
  1511.             }
  1512.             imagecopy($img$src_img0,0,0,0,imagesx($src_img)imagesy($src_img));
  1513.             $src_img $img;
  1514.         }
  1515.         return $src_img;
  1516.     }
  1517.  
  1518.     /**
  1519.      *  ¾×ÀÚ½ºÅ² ¼³Á¤Çϱâ
  1520.      *
  1521.      * @param  resource ´ë»ó À̹ÌÁö
  1522.      * @param  String     ¾×ÀÚ½ºÅ²¸í
  1523.      * @return  resource    BufferedImage
  1524.     */
  1525.     function setSkin($img$frmName){
  1526.         $skininfo $this->loadSkin($frmName);
  1527.         $img_width imagesx($img);
  1528.         $img_height imagesy($img);
  1529.         if ($skininfo['skinimg'== '')
  1530.             return $img;
  1531.         $frm_img $this->load('skin/'.$skininfo['skinimg']);
  1532.         $resize_rate 1;
  1533.         $original_img null;
  1534.         if ($skininfo['type'!= 'transparent_fit'{
  1535.             if ($img_width $skininfo['extraspace_0'imagesx($frm_img|| $img_height $skininfo['extraspace_1'imagesy($frm_img)) {
  1536.                 if ((imagesx($frm_img$skininfo['extraspace_0']&& (imagesy($frm_img$skininfo['extraspace_1']0)
  1537.                     $resize_rate min($img_width/(imagesx($frm_img$skininfo['extraspace_0'])$img_height/(imagesy($frm_img$skininfo['extraspace_1']));
  1538.                 else
  1539.                     $resize_rate 1;
  1540.                 if ($resize_rate && $resize_rate != 1{
  1541.                     $original_img $img;
  1542.                     $img $this->resize($imgimagesx($img)/$resize_rateimagesy($img)/$resize_rate);
  1543.                     $img_width imagesx($img);
  1544.                     $img_height imagesy($img);
  1545.                 }
  1546.             }
  1547.         }
  1548.         
  1549.         $frm_width $img_width $skininfo['extraspace_0';
  1550.         $frm_height $img_height $skininfo['extraspace_1'];
  1551.         
  1552.         $this->img = $this->getImg($frm_width$frm_heighttrue);
  1553.         $frm_y $frm_x 0;
  1554.         $img_y $img_x 0;
  1555.         if ($skininfo['type'== 'transparent_fit'{
  1556.             imagecopyresized($this->img$frm_img000,0$frm_width$frm_heightimagesx($frm_img)imagesy($frm_img));
  1557.         else {
  1558.             if ($skininfo['type'!= '')
  1559.                 $this->copy($img$skininfo['pic_drawpt_0']$skininfo['pic_drawpt_1']);
  1560.             if ($skininfo['upleft_0'&& $skininfo['upleft_1'0)
  1561.                 $this->copy($frm_img$img_x$img_y$skininfo['upleft_0']$skininfo['upleft_1']$frm_x$frm_y);
  1562.             $frm_x += $skininfo['upleft_0'];
  1563.             $img_x += $skininfo['upleft_0'];
  1564.             $mid_width $frm_width $skininfo['upleft_0'$skininfo['upright_0'];
  1565.             if ($mid_width 0){
  1566.                 if ($skininfo['upmid_0'&& $skininfo['upmid_1'0)
  1567.                     $this->fillCopy($frm_img$frm_x$frm_y$skininfo['upmid_0'],$skininfo['upmid_1']$img_x$img_y$mid_width$skininfo['upmid_1']$skininfo['stretch_mode']);
  1568.                 $img_x += $mid_width;
  1569.             }
  1570.             $frm_x += $skininfo['upmid_0'];
  1571.             if ($skininfo['upright_0'&& $skininfo['upright_1'0)
  1572.                 $this->copy($frm_img$img_x$img_y$skininfo['upright_0']$skininfo['upright_1']$frm_x$frm_ytrue);
  1573.             $frm_y += $skininfo['upleft_1'];
  1574.             $frm_x 0;
  1575.             $img_y += $skininfo['upleft_1'];
  1576.             $img_x 0;
  1577.             $mid_height $frm_height $skininfo['upleft_1'$skininfo['btleft_1'];
  1578.             if ($mid_height 0{
  1579.                 if ($skininfo['ctleft_1'&& $skininfo['ctleft_1'0)
  1580.                     $this->fillCopy($frm_img$frm_x$frm_y$skininfo['ctleft_0'],$skininfo['ctleft_1']$img_x$img_y$skininfo['ctleft_0'],$mid_height$skininfo['stretch_mode']);
  1581.                 $frm_x += $skininfo['ctleft_0'$skininfo['upmid_0';
  1582.                 $img_x += $skininfo['ctleft_0']$mid_width;
  1583.                 if ($skininfo['ctright_1'&& $skininfo['ctright_1'0)
  1584.                     $this->fillCopy($frm_img$frm_x$frm_y$skininfo['ctright_0'],$skininfo['ctright_1']$img_x$img_y$skininfo['ctright_0'],$mid_height$skininfo['stretch_mode']);
  1585.                 $frm_x 0;
  1586.                 $img_x 0;
  1587.                 $img_y += $mid_height;
  1588.             }
  1589.             $frm_y += $skininfo['ctleft_1'];
  1590.             if ($skininfo['btleft_0'&& $skininfo['btleft_1'0)
  1591.                 $this->copy($frm_img$img_x$img_y$skininfo['btleft_0']$skininfo['btleft_1']$frm_x$frm_ytrue);
  1592.             $frm_x += $skininfo['btleft_0'];
  1593.             $img_x += $skininfo['btleft_0'];
  1594.             $mid_width $frm_width $skininfo['btleft_0'$skininfo['btright_0'];
  1595.             if ($mid_width 0){
  1596.                 if ($skininfo['btmid_0'&& $skininfo['btmid_1'0)
  1597.                     $this->fillCopy($frm_img$frm_x$frm_y$skininfo['btmid_0'],$skininfo['btmid_1']$img_x$img_y$mid_width$skininfo['btmid_1']$skininfo['stretch_mode']);
  1598.                 $img_x += $mid_width;
  1599.             }
  1600.             $frm_x += $skininfo['btmid_0'];
  1601.             if ($skininfo['btright_0'&& $skininfo['btright_1'0)
  1602.                 $this->copy($frm_img$img_x$img_y$skininfo['btright_0']$skininfo['btright_1']$frm_x$frm_y,true);
  1603.         }        
  1604.         if ($skininfo['type'!= 'transparent_fit'{
  1605.             if ($original_img == null)
  1606.                 $original_img $img
  1607.             if ($resize_rate && $resize_rate != 1
  1608.                 $this->img = $this->resize($this->imgimagesx($this->img)*$resize_rateimagesy($this->img)*$resize_rate);
  1609.             if ($skininfo['type'== ''
  1610.                 $this->copy($original_img$skininfo['pic_drawpt_0']*$resize_rate$skininfo['pic_drawpt_1']*$resize_rate);
  1611.         }
  1612.         return $this->img;
  1613.     }
  1614.  
  1615.     /**
  1616.      *  ÇöÀçÀÇ À̹ÌÁö¿¡ º¹»ç ³Ö±â
  1617.      *
  1618.      * @param  resource º¹»çÇÒÀ̹ÌÁö
  1619.      * @param  Int °¡·Î¼¼·Î ¿©¹é
  1620.     */
  1621.     function setImg($img$padding){
  1622.         $ow imagesx($this->img$padding *2;
  1623.         $img $this->resize($img$ow);
  1624.         $this->text_y = imagesy($img$padding *1.5;
  1625.         $this->text_x = $padding;
  1626.         $this->copy($img$padding$padding);
  1627.     }
  1628.  
  1629.     /**
  1630.      *  ÇöÀçÀÇ À̹ÌÁö¿¡ ¹®ÀÚ ³Ö±â
  1631.      *
  1632.      * @param  String        ¹®ÀÚ
  1633.      * @param  String     ¹®ÀÚ »ö»ó
  1634.     */
  1635.     function setText($text$hexcolor){
  1636.         $this->text($text$this->text_x$this->text_y$hexcolor);
  1637.         $this->text_y += 15;
  1638.     }
  1639.  
  1640.     /**
  1641.      *  ÁÖ¾îÁø À̹ÌÁö È¸Àü
  1642.      *
  1643.      * @param  resource ´ë»ó À̹ÌÁö
  1644.      * @param  Int È¸Àü°¢µµ(1: 90µµ, 2: 180µµ, 3: 270µµ, 0 :ȸÀü¾øÀ½)
  1645.      * @return  resource    BufferedImage
  1646.     */
  1647.     function setRotate($img$degree){
  1648.         if ($degree == 0)
  1649.             return $img;
  1650.         if (imagesx($img1024)
  1651.             $img $this->resize($img1024);
  1652.         return imagerotate($img$degree*900);
  1653.     }    
  1654.     
  1655.     /**
  1656.      *  À̹ÌÁö¿¡ ÇÁ·¹ÀÓÃß°¡Çϱâ
  1657.      *
  1658.      * @param  String À̹ÌÁöÆÄÀϸí
  1659.      * @param  String ÇÁ·¹ÀÓ¸í
  1660.      * @param  Int ÃÖ´ëÆø
  1661.      * @param  Boolean ÀÚµ¿È¸Àü¿©ºÎ
  1662.      * @param  String ¹è°æ»ö»ó
  1663.      * @param  String ¶óÀλö»ó
  1664.      * @param  String ±Û¾¾»ö»ó
  1665.      * @param  String À̹ÌÁö½ÎÀÎ
  1666.      * @param  Boolean »çÁøÃÔ¿µÁ¤º¸ ³Ö±â¿©ºÎ
  1667.      * @param  Int ÇÁ·¹ÀÓ ¿©¹é
  1668.     */
  1669.     function makeFrame($file_name$img_style$max_width$auto_rotate$bgcolor$linecolor$fontcolor$sign  $add_picinfo$padding_value{
  1670.         $img $this->load($file_name);
  1671.         $addheight 0;
  1672.         $photo_info "";
  1673.         $photo_model "";
  1674.         if ($add_picinfo || $auto_rotate{
  1675.             $exif new rainExif($file_name);
  1676.             $photo_model $exif->getModel();
  1677.             if ($photo_model != ""{
  1678.                 $photo_info $exif->getInfo();
  1679.                 $addheight += 30;
  1680.             }
  1681.             if ($auto_rotate
  1682.                 $img $this->setRotate($img$exif->getRotate());
  1683.         }
  1684.         if ($sign != ""
  1685.             $addheight += 15;
  1686.         if (imagesx($img$max_width)
  1687.             $img $this->resize($img$max_width);
  1688.         $frmWidth imagesx($img$padding_value *2;
  1689.         $frmHeight imagesy($img$padding_value *$addheight;
  1690.         $this->img = $this->getImg($frmWidth$frmHeight);
  1691.         $this->setFrame($img_style);
  1692.         $this->setImg($img$padding_value);
  1693.         if ($sign != ""
  1694.             $this->setText($sign$fontcolor);
  1695.         if ($photo_model != ""
  1696.             $this->setText($photo_model$fontcolor);
  1697.         if ($photo_info != ""
  1698.             $this->setText($photo_info$fontcolor);
  1699.         $this->save($file_name);
  1700.     }
  1701.  
  1702.     /**
  1703.      *  ÆÄÀÏ¸í¿¡¼­ È®ÀåÀÚ °¡Á®¿À±â
  1704.      *
  1705.      * @param  String         ´ë»óÆÄÀϸí
  1706.      * @param  Boolean     ÀÚ¹ÙÇü À̹ÌÁö¿©ºÎ
  1707.      * @return  String            ÆÄÀÏÈ®ÀåÀÚ
  1708.     */
  1709.     function name2Ext($fileName$java_img false{
  1710.         $tar_file_extension "";
  1711.         if ($fileName == ""{
  1712.             if (ereg("\.([^\.]+)$"$fileName$tmp_reg)) 
  1713.                 $tar_file_extension substr(strtolower($tmp_reg[1])04);
  1714.             else 
  1715.                 $tar_file_extension "tmp";
  1716.         }
  1717.         if ($java_img && $tar_file_extension == 'gif')
  1718.             $tar_file_extension 'png';
  1719.         return $tar_file_extension;
  1720.     }
  1721.  
  1722.     /**
  1723.      *  ÇöÀçÀÇ À̹ÌÁö¸¦ ÁÖ¾îÁø ÆÄÀϸíÀ¸·Î ÀúÀå
  1724.      *
  1725.      * @param  String     ´ë»óÆÄÀϸí
  1726.      * @return  Boolean    ¼º°ø¿©ºÎ
  1727.     */
  1728.     function save($fileName$img_type 'png'{
  1729.           if (rainUtil::checkDir($this->getBaseRoot()$fileName)) {
  1730.             $fileext ($img_type == '')$this->name2Ext($fileNametrue$img_type;
  1731.             switch($fileext{
  1732.                 case 'png' :
  1733.                     @imagepng($this->img$this->getBaseRoot($fileName);
  1734.                     break;
  1735.                 case 'jpeg' :
  1736.                 case 'jpg' :
  1737.                     @imagejpeg($this->img$this->getBaseRoot($fileName);
  1738.                     break;
  1739.                 case 'bwp' :
  1740.                     @imagewbmp($this->img$this->getBaseRoot($fileName);
  1741.                     break;
  1742.                 default 
  1743.                     @imagepng($this->img$this->getBaseRoot($fileName);
  1744.                     break;
  1745.             }
  1746.             return true;
  1747.         else
  1748.             return false;
  1749.     }
  1750.  
  1751.     /**
  1752.      *  ÇöÀçÀÇ À̹ÌÁö¸¦ À¥ºê¶ó¿ìÀú·Î Àü¼Û
  1753.      *
  1754.      * @param  String À̹ÌÁö ÆÄÀϸí
  1755.      * @param  resource À̹ÌÁö°´Ã¼
  1756.     */
  1757.     function show($imgName ''$img null{
  1758.         $show_img null;
  1759.         if ($imgName == '' && $img != null
  1760.             $show_img$img;
  1761.         else if ($imgName != ''
  1762.             $show_img$this->load($imgName);
  1763.         else
  1764.             $show_img $this -> img;
  1765.         header("Content-type: " image_type_to_mime_type(IMAGETYPE_PNG));
  1766.         imagepng($show_img);
  1767.     }
  1768.  
  1769.     /**
  1770.      *  ±×·¹ÀÌ È¿°úÁÖ±â
  1771.      *
  1772.      * @param  resource  ´ë»ó À̹ÌÁö
  1773.     */
  1774.     function filterGray(&$image{
  1775.         $imagex imagesx($image);
  1776.         $imagey imagesy($image);
  1777.         for ($x 0$x <$imagex++$x{
  1778.             for ($y 0$y <$imagey++$y{
  1779.                 $rgb imagecolorat($image$x$y);
  1780.                 $red ($rgb >> 16255;
  1781.                 $green ($rgb >> 8255;
  1782.                 $blue $rgb 255;
  1783.                 $grey = (int)(($red+$green+$blue)/3);
  1784.                 $newcol imagecolorallocate($image$grey,$grey,$grey);
  1785.                 imagesetpixel($image$x$y$newcol);
  1786.             }
  1787.         }
  1788.     }
  1789.  
  1790.     /**
  1791.      *  µàÅæ È¿°úÁÖ±â
  1792.      *
  1793.      * @param  resource  ´ë»ó À̹ÌÁö
  1794.      * @param  Int  Àû»ö ÂüÁ¶°ª(0-255)
  1795.      * @param  Int  ±×¸° ÂüÁ¶°ª(0-255)
  1796.      * @param  Int  ºí·ç ÂüÁ¶°ª(0-255)
  1797.      * @return  resource    BufferedImage
  1798.     */
  1799.     function filterDuotone (&$image$rplus$gplus$bplus{
  1800.         $imagex imagesx($image);
  1801.         $imagey imagesy($image);
  1802.     
  1803.         for ($x 0$x <$imagex++$x{
  1804.             for ($y 0$y <$imagey++$y{
  1805.                 $rgb imagecolorat($image$x$y);
  1806.                 $red ($rgb >> 160xFF;
  1807.                 $green ($rgb >> 80xFF;
  1808.                 $blue $rgb 0xFF;
  1809.                 $red = (int)(($red+$green+$blue)/3);
  1810.                 $green $red $gplus;
  1811.                 $blue $red $bplus;
  1812.                 $red += $rplus;
  1813.                 $red $this->getSafeColor($red);
  1814.                 $green $this->getSafeColor($green);
  1815.                 $blue $this->getSafeColor($blue);
  1816.                 $newcol imagecolorallocate ($image$red,$green,$blue);
  1817.                 imagesetpixel ($image$x$y$newcol);
  1818.             }
  1819.         }
  1820.     
  1821.  
  1822.     /**
  1823.      * ³ëÀÌÁî È¿°úÁÖ±â
  1824.      *
  1825.      * @param  resource  ´ë»ó À̹ÌÁö
  1826.      * @param  Int  ³ëÀÌÁîºñÀ²(1 ÃÖ´ë)
  1827.     */
  1828.     function filterNoise (&$image$noise 1{
  1829.         $imagex imagesx($image);
  1830.         $imagey imagesy($image);
  1831.         for ($x 0$x $imagex++$x{
  1832.             for ($y 0$y $imagey++$y{
  1833.                 if (rand(0,$noise)) {
  1834.                     $rgb imagecolorat($image$x$y);
  1835.                     $red ($rgb >> 160xFF;
  1836.                     $green ($rgb >> 80xFF;
  1837.                     $blue $rgb 0xFF;
  1838.                     $modifier rand(-20,20);
  1839.                     $red += $modifier;
  1840.                     $green += $modifier;
  1841.                     $blue += $modifier;
  1842.                     $red $this->getSafeColor($red);
  1843.                     $green $this->getSafeColor($green);
  1844.                     $blue $this->getSafeColor($blue);
  1845.                     $newcol imagecolorallocate($image$red$green$blue);
  1846.                     imagesetpixel($image$x$y$newcol);
  1847.                 }
  1848.             }
  1849.         }
  1850.     
  1851.  
  1852.     /**
  1853.      * ÀÜ»óÈ¿°ú È¿°úÁÖ±â
  1854.      *
  1855.      * @param  resource  ´ë»ó À̹ÌÁö
  1856.      * @param  Int  ÀÜ»ó°Å¸®
  1857.     */
  1858.     function filterScatter(&$image$dist 4{
  1859.         $imagex imagesx($image);
  1860.         $imagey imagesy($image);
  1861.         for ($x 0$x $imagex++$x{
  1862.             for ($y 0$y $imagey++$y{
  1863.                 $distx rand($dist *(-1)$dist);
  1864.                 $disty rand($dist *(-1)$dist);
  1865.                 if ($x $distx >= $imagexcontinue;
  1866.                 if ($x $distx 0continue;
  1867.                 if ($y $disty >= $imageycontinue;
  1868.                 if ($y $disty 0continue;
  1869.                 $oldcol imagecolorat($image$x$y);
  1870.                 $newcol imagecolorat($image$x $distx$y $disty);
  1871.                 imagesetpixel($image$x$y$newcol);
  1872.                 imagesetpixel($image$x $distx$y $disty$oldcol);
  1873.             }
  1874.         }
  1875.     
  1876.     
  1877.     /**
  1878.      *  Çʼ¿·¹ÀÌÆ® È¿°úÁÖ±â
  1879.      *
  1880.      * @param  resource  ´ë»ó À̹ÌÁö
  1881.      * @param  Int  ºí·°Å©±â
  1882.      * @return  resource    BufferedImage
  1883.     */
  1884.     function filterPixelate(&$image$blocksize 12{
  1885.         $imagex imagesx($image);
  1886.         $imagey imagesy($image);
  1887.         for ($x 0$x $imagex$x += $blocksize{
  1888.             for ($y 0$y $imagey$y += $blocksize{
  1889.                 $rgb imagecolorat($image$x$y);
  1890.                 imagefilledrectangle($image$x$y$x $blocksize 1$y $blocksize 1$rgb);
  1891.             }
  1892.         }
  1893.     }
  1894.  
  1895.     /**
  1896.      *  ¼¼ÇǾƠȿ°úÁÖ±â
  1897.      *
  1898.      * @param  resource  ´ë»ó À̹ÌÁö
  1899.      * @param  String  ÂüÁ¶»ö»ó
  1900.      * @return  resource    BufferedImage
  1901.     */
  1902.     function effectSepia($image,$base_color '#464646'{
  1903.         list($b_red$b_green$b_blue$this->hex2Int($base_color);
  1904.         $red_table Array();
  1905.         $green_table Array();
  1906.         $blue_table Array();
  1907.         for($i 0$i 256$i++{
  1908.             $red_table[$iround($i (255 $i)*$b_red/255);
  1909.             $green_table[$iround($i (255 $i)*$b_green/255);
  1910.             $blue_table[$iround($i (255 $i)*$b_blue/255);
  1911.         }
  1912.         $imagex imagesx($image);
  1913.         $imagey imagesy($image);
  1914.         for ($x 0$x $imagex$x++{
  1915.             for ($y 0$y $imagey$y++{
  1916.                 $rgb imagecolorat($image$x$y);
  1917.                 $red ($rgb >> 16255;
  1918.                 $green ($rgb >> 8255;
  1919.                 $blue $rgb 255;
  1920.                 $nred $red_table[$red];
  1921.                 $ngreen $green_table[$green];
  1922.                 $nblue $blue_table[$blue];
  1923.                 $newcol imagecolorallocate($image$nred,$ngreen,$nblue);
  1924.                 imagesetpixel($image$x$y$newcol);
  1925.             }
  1926.         }
  1927.         return $image;
  1928.     }
  1929.  
  1930.     /**
  1931.      *  Ä¿³Ú °¡Á®¿À±â
  1932.      *
  1933.      * @param  String  Ä¿³ÚÇüÅÂ
  1934.      * @param  Int  ÂüÁ¶ ·¹º§
  1935.      * @return  Array    Kernel
  1936.     */
  1937.     function getKernel($kernel_type$level 1{
  1938.         switch($kernel_type{
  1939.             case 'B' :
  1940.                 $kernel Array(
  1941.                     0.06250.1250.0625
  1942.                     0.1250.250.125,
  1943.                     0.06250.1250.0625
  1944.                 );
  1945.                 break;
  1946.             case 'S' :
  1947.                 $kernel Array(
  1948.                     0.0 -0.125 0.0 
  1949.                     -0.125 ,  1.5 -0.125 
  1950.                     0.0 -0.125 ,  0.0
  1951.                 );
  1952.                 break;
  1953.             case 'E' :
  1954.             default :
  1955.                 $kernel Array(
  1956.                     2.00.0-2.0
  1957.                     2.01.0-2.0
  1958.                     2.0 0.0 ,-2.0
  1959.                 );
  1960.                 break;
  1961.         }
  1962.         if ($level == 1)
  1963.             return $kernel;
  1964.         else {
  1965.             foreach($kernel as $key => $val
  1966.                 $kernel[$key1/(1/$val)/($level);
  1967.             return $kernel;
  1968.         }
  1969.     }
  1970.  
  1971.     /**
  1972.      *  ÇÊÅÍ LookupTable °ü·Ã
  1973.      *
  1974.      * @param resource ´ë»óÀ̹ÌÁö
  1975.      * @param Array    lookup  ÂüÁ¶Å×À̺í
  1976.     */
  1977.     function filterLookupTable(&$image$lookup Array()) {
  1978.         $imagex imagesx($image);
  1979.         $imagey imagesy($image);
  1980.         for ($x 0$x $imagex$x++{
  1981.             for ($y 0$y $imagey$y++{
  1982.                 $rgb imagecolorat($image$x$y);
  1983.                 $red $lookup[($rgb >> 16255];
  1984.                 $green $lookup[($rgb >> 8255];
  1985.                 $blue $lookup[$rgb 255];
  1986.                 $newcol imagecolorallocate($image$red,$green,$blue);
  1987.                 imagesetpixel($image$x$y$newcol);
  1988.             }
  1989.         }
  1990.     }
  1991.  
  1992.     /**
  1993.      *  ÇÊÅÍ ConvolveOp °ü·Ã
  1994.      *
  1995.      * @param resource ´ë»óÀ̹ÌÁö
  1996.      * @param Array kernel  ÂüÁ¶Å×À̺í
  1997.     */
  1998.     function filterConvolveOp(&$image$kernel Array()) {
  1999.         $imagex imagesx($image);
  2000.         $imagey imagesy($image);
  2001.         $dist 1;
  2002.         $color_matrix Array();
  2003.         for ($x 0$x $imagex++$x
  2004.             for ($y 0$y $imagey++$y
  2005.                 $color_matrix[$x][$y=     imagecolorat($image$x$y);
  2006.         for ($x 0$x $imagex++$x{
  2007.             for ($y 0$y $imagey++$y{
  2008.                 $newr 0;
  2009.                 $newg 0;
  2010.                 $newb 0;
  2011.                 $colours array();
  2012.                 $thiscol $color_matrix[$x][$y];
  2013.                 for ($k $x $dist$k <= $x $dist++$k{
  2014.                     for ($l $y $dist$l <= $y $dist++$l{
  2015.                         if ($k 0$colours[$thiscolcontinue}
  2016.                         if ($k >= $imagex$colours[$thiscolcontinue}
  2017.                         if ($l 0$colours[$thiscolcontinue}
  2018.                         if ($l >= $imagey$colours[$thiscolcontinue}
  2019.                         $colours[$color_matrix[$k][$l];
  2020.                     }
  2021.                 }
  2022.                 foreach($colours as $i => $colour{
  2023.                     $newr += (($colour >> 160xFF$kernel[$i;
  2024.                     $newg += (($colour >> 80xFF$kernel[$i];
  2025.                     $newb += ($colour 0xFF$kernel[$i];
  2026.                 }
  2027.                 $newr $this->getSafeColor($newr);
  2028.                 $newg $this->getSafeColor($newg);
  2029.                 $newb $this->getSafeColor($newb);
  2030.                 $newcol imagecolorallocate($image$newr$newg$newb);
  2031.                 imagesetpixel($image$x$y$newcol);
  2032.             }
  2033.         }
  2034.     
  2035.  
  2036.     /**
  2037.      *  »ö»óÁ¶Á¤ - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectColor ¿Í µ¿ÀÏ)
  2038.      *
  2039.      * @param resource ´ë»óÀ̹ÌÁö
  2040.      * @param Int Á¶Á¤¹üÀ§ [-255~ +255]
  2041.     */
  2042.     function filterColor(&$image$hue 0{
  2043.         if ($rate != 0{
  2044.             $lookup Array();
  2045.             for($x 0$i 256$i++
  2046.                 $lookup[$i$this->getSafeColor($i $rate);
  2047.             $this->filterLookupTable(&$image$lookup);    
  2048.         }
  2049.     }
  2050.  
  2051.     /**
  2052.      *  ³×°¡Æ¼ºêÈ¿°ú - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectReverse ¿Í µ¿ÀÏ)
  2053.      *
  2054.      * @param resource ´ë»óÀ̹ÌÁö
  2055.     */
  2056.     function filterReverse(&$image{
  2057.         $lookup Array();
  2058.         for($x 0$i 256$i++
  2059.             $lookup[$i255 $i;
  2060.         $this->filterLookupTable(&$image$lookup);
  2061.     }
  2062.     
  2063.     /**
  2064.      *  ¹à±â Á¶Á¤ - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectBrighten ¿Í À¯»ç)
  2065.      *
  2066.      * @param resource ´ë»óÀ̹ÌÁö
  2067.      * @param  Int  Á¶Á¤¹üÀ§ [-255~ +255]
  2068.     */
  2069.     function filterBrighten(&$image$bright 0{
  2070.         if ($bright != 0{
  2071.             $lookup Array();
  2072.             for($x 0$i 256$i++
  2073.                 $lookup[$i$this->getSafeColor($i $bright);
  2074.             $this->filterLookupTable(&$image$lookup);    
  2075.         }
  2076.     }
  2077.  
  2078.     /**
  2079.      *  ÄÁÆ®¶ó½ºÅÍ Á¶Á¤ - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectContrast ¿Í µ¿ÀÏ)
  2080.      *
  2081.      * @param resource ´ë»óÀ̹ÌÁö
  2082.      * @param  Int  Á¶Á¤¹üÀ§ [-255~ +255]
  2083.     */
  2084.     function filterContrast(&$image$cont 0{
  2085.         $cont_rate =  ($cont/1000.5;
  2086.         if ($cont_rate != 0{
  2087.             $lookup Array();
  2088.             for($x 0$i 256$i++
  2089.                 $lookup[$i$this->getSafeColor($i (1$cont_rate));
  2090.             $this->filterLookupTable(&$image$lookup);    
  2091.         }
  2092.     }
  2093.     
  2094.     /**
  2095.      *  ºí·¯È¿°ú - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectBlur ¿Í µ¿ÀÏ)
  2096.      *
  2097.      * @param resource ´ë»óÀ̹ÌÁö
  2098.      * @param  Int  Á¶Á¤¹üÀ§ [1-5]
  2099.     */
  2100.     function filterBlur(&$image$level 1{
  2101.         $kernel $this->getKernel('B',$level);
  2102.         $this->filterConvolveOp(&$image$kernel);
  2103.     
  2104.  
  2105.     /**
  2106.      *  »þÆÝÈ¿°ú - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectSharpen ¿Í µ¿ÀÏ)
  2107.      *
  2108.      * @param resource ´ë»óÀ̹ÌÁö
  2109.      * @param  Int  Á¶Á¤¹üÀ§ [1-5]
  2110.     */
  2111.     function filterSharpen(&$image$level 1{
  2112.         $kernel $this->getKernel('S',1/$level);
  2113.         $this->filterConvolveOp(&$image$kernel);
  2114.     
  2115.  
  2116.     /**
  2117.      *  ¿¡ÁöÈ¿°ú - PHP 5 ¹öÀü ÀÌÇÏ¿ë(effectEdge ¿Í µ¿ÀÏ)
  2118.      *
  2119.      * @param resource ´ë»óÀ̹ÌÁö
  2120.      * @param  Int  Á¶Á¤¹üÀ§ [1-5]
  2121.     */
  2122.     function filterEdge(&$image$level 1{
  2123.         $kernel $this->getKernel('E',$level);
  2124.         $this->filterConvolveOp(&$image$kernel);
  2125.     
  2126.  
  2127. }
  2128.  
  2129. ?>

Documentation generated on Mon, 17 Mar 2008 12:17:51 +0900 by phpDocumentor 1.4.0a2 | Copyright 2005 cafen.net