debugstring = array(); } /** * デバッグオプションを設定する。 * @access public * @param boolean $debugmode デバッグ描画モード(ON/OFF) * @param int $debugfontsize デバッグメッセージ描画フォントサイズ * @param string $debugcolor デバッグメッセージフォントカラー * @param int $debugfont デバッグメッセージフォントファイル(FreeType Font使用時) */ public function setDebugOptions($debugmode=FALSE,$debugfontsize=3,$debugfontcolor='black',$debugbgcolor='white',$debugfont=''){ $this->debugmode = $debugmode; $this->debugfontsize = $debugfontsize; $this->debugfontcolor = $debugfontcolor; $this->debugfont = $debugfont; $this->debugbgcolor = $debugbgcolor; } /** * デバッグストリングを追加する。 * @access public * @param string 追加メッセージ * @param int 次行フラグ(同行=0、次行=1) */ public function addDebugMessage($message,$next=0){ if(!(count($this->debugstring))){ $this->debugstring = array($message); }elseif($next){ array_push($this->debugstring,$message); }else{ $this->debugstring[count($this->debugstring)-1] .= $message; } } /** * デバッグスケールを追加する。 * @access public */ public function drawDebugScales(){ } /** * デバッグストリングをログに出力する。 * @access public * @param object $log ログファイルオブジェクト */ public function outputDebugMessageToLog($log){ if(count($this->debugstring)){ $log->logInfo("[[Debug String]]]\n"); foreach($this->debugstring as $string){ // self::log_info($string) $log->logInfo($string); } } } /** * デバッグストリングを描画する。 * @access public * @param resource $image イメージリソース * @param int $fontsize 文字サイズ * @param int $fontsize 文字色 * @return resource イメージリソース */ public function drawDebugMessage($image){ $sy = imagesy($image); // imagefttext($img,$fontsize,0,$x,$y,$black,'C:\WINDOWS\Fonts\COUR.TTF',$string); // $array = imageftbbox($fontsize,0,'C:\WINDOWS\Fonts\COUR.TTF',$string); if($this->debugfont){ $min = 0; $max = 0; foreach($this->debugstring as $message){ $array = imageftbbox($this->debugfontsize,0,$this->debugfont,$message); if($array[5] < $min){ $min = $array[5]; } if($array[1] > $max){ $max = $array[1]; } } $string_height = abs($min) + $max; $extend_height = $string_height*count($this->debugstring); $image = self::extendImageHeight($image,$extend_height,$this->debugbgcolor); for($i=0;$idebugstring);$i++){ $x = 0; $y = $sy + abs($min)*($i+1)+$max*$i; $col_array = ColorUtil::getRGB($this->debugfontcolor); $col = imagecolorallocate($image,$col_array[0],$col_array[1],$col_array[2]); imagettftext($image,$this->debugfontsize,0,$x,$y,$col,$this->debugfont,$this->debugstring[$i]); // imagestring($this->image,$fontsize,$x,$y,$this->debugstring[$i],$col); } }else{ $string_height= imagefontheight($this->debugfontsize); $extend_height = $string_height*count($this->debugstring); $image = self::extendImageHeight($image,$extend_height,$this->debugbgcolor); for($i=0;$idebugstring);$i++){ $x = 0; $y = $sy + $string_height*$i; $col_array = ColorUtil::getRGB($this->debugfontcolor); $col = imagecolorallocate($image,$col_array[0],$col_array[1],$col_array[2]); imagestring($image,$this->debugfontsize,$x,$y,$this->debugstring[$i],$col); } } return $image; } private function extendImageHeight($image,$extend_height,$bgcolor='white'){ //拡張する高さチェック if($extend_height <=0){ return $image; } //古いサイズ(描画枠) $width = imagesx($image); $height = imagesy($image); //新しいサイズ(画像枠) $new_width = $width; $new_height = $height + $extend_height; //新規イメージリソース作成 $newimage = imagecreatetruecolor($new_width,$new_height); //背景をbgcolorでフィル $colarray = ColorUtil::getRGB($bgcolor); $bgcol = imagecolorallocate($image,$colarray[0],$colarray[1],$colarray[2]); imagefill($newimage,0,0,$bgcol); //コピー位置 $dst_x = 0; $dst_y = 0; $src_x = 0; $src_y = 0; $src_w = $width; $src_h = $height; //新規イメージリソースに旧リイメージをコピー imagecopy($newimage,$image,$dst_x,$dst_y,$src_x,$src_y,$src_w,$src_h); //旧イメージリソースの解放 imagedestroy($image); //イメージリソースを返す return $newimage; } public function isDebugMode(){ return $this->debugmode; } } ?>