protected function _aGetRegionArr($sRegion) { $regions = preg_split('/;|,|\\s/', $sRegion); $ret = array(); foreach ($regions as $region) { $region = trim($region); if (0 === strlen($region)) { continue; } $region = Ko_Tool_Str::AStr2Arr($region, $this->_aConf['isgb'] ? 'GB18030' : 'UTF-8'); $region = implode('', array_slice($region, 0, 2)); if (!$this->_aConf['isgb']) { $region = Ko_Tool_Str::SConvert2GB18030($region); } $ret[] = $region; } return $ret; }
private static function _IWritePhrase($image, $phrase, $font, $fontsize, $width, $height, $textcolor, $maxangle, $maxoffset) { $size = abs(intval($fontsize)); if ($size === 0) { $size = $width / strlen($phrase) - mt_rand(0, 3) - 1; } $box = imagettfbbox($size, 0, $font, $phrase); $textWidth = $box[2] - $box[0]; $textHeight = $box[1] - $box[7]; $x = ($width - $textWidth) / 2; $y = ($height - $textHeight) / 2 + $size; if (!count($textcolor)) { $textColor = array(mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150)); } else { $textColor = $textcolor; } $color = imagecolorallocate($image, $textColor[0], $textColor[1], $textColor[2]); $phraseChar = Ko_Tool_Str::AStr2Arr($phrase); foreach ($phraseChar as $char) { $box = imagettfbbox($size, 0, $font, $char); $pos = $box[2] - $box[0]; $angle = mt_rand(-$maxangle, $maxangle); $offset = mt_rand(-$maxoffset, $maxoffset); imagettftext($image, $size, $angle, $x, $y + $offset, $color, $font, $char); $x += $pos; } return $color; }