{"id":379,"title":"php\u751f\u6210\u56fe\u7247\u53ca\u6587\u5b57\u6c34\u5370","good":0,"bad":0,"hit":1260,"created_at":"2018-08-01 17:43:16","content":"
\u573a\u666f\uff1a\u7f51\u7ad9\u7edf\u8ba1\u4ee3\u7801\uff0c\u5728\u7528\u6237\u7f51\u7ad9\u662f\uff0c\u6839\u636e\u4e00\u4e2a\u5b57\u6bb5\u503c\uff0c\u663e\u793a\u56fe\u7247\u6216\u6587\u5b57\u6c34\u5370\u56fe\u7247icon<\/p>
<\/p>
public function createIcon($icon)\n{\n \/\/\u56fe\u6807\u7c7b\u578b 0:\u4e0d\u663e\u793a 1:\u9ed8\u8ba4 2:\u9ed8\u8ba4(\u7bee\u8272) 3:\u9ed8\u8ba4(\u7eff) 4:\u9ed8\u8ba4(\u7d2b) 10:\u6587\u5b57\u663e\u793a\n\n $config = config('img');\n\n $width = $config['width'];\n $widthTxt = $config['width_txt'];\n $height = $config['height'];\n\n $bgRed = $config['bg_red'];\n $bgGreen = $config['bg_green'];\n $bgBlue = $config['bg_blue'];\n\n $textRed = $config['text_red'];\n $textGreen = $config['text_green'];\n $textBlue = $config['text_blue'];\n $ds = DIRECTORY_SEPARATOR;\n $rootDir = $_SERVER['DOCUMENT_ROOT'];\n\n \/\/\u56fe\u7247\u6216\u6587\u5b57\u65f6\uff0c\u663e\u793a\u7684\u5bbd\u5ea6\u4e0d\u4e00\u6837\n $hbWidth = $icon == 10 ? $widthTxt : $width;\n\n \/\/\u753b\u5e03\n if (function_exists('imagecreatetruecolor')) {\n $hb = imagecreatetruecolor($hbWidth, $height);\n } else {\n $hb = imagecreate($hbWidth, $height);\n }\n\n if ($icon > 0 && $icon <= 4) {\n \/\/\u663e\u793aicon\u56fe\u7247\n $img = $rootDir . $ds . 'source' . $ds . 'img' . $ds . $this->img[$icon];\n $source = imagecreatefrompng($img);\n imagecopyresampled($hb, $source, 0, 0, 0, 0, $width, $height, $width, $height);\n imagepng($hb);\n imagedestroy($source);\n } else if ($icon == 10) {\n \/\/\u663e\u793a\u6587\u5b57icon\n \/\/\u56fe\u7247\u80cc\u666f\n $background = imagecolorallocate($hb, $bgRed, $bgGreen, $bgBlue);\n \/\/\u586b\u5145\u80cc\u666f\n imagefill($hb, 0, 0, $background);\n \/\/\u5b57\u4f53\u989c\u8272\n $black = imagecolorallocate($hb, $textRed, $textGreen, $textBlue);\n \/\/\u5b57\u4f53\u6587\u4ef6\n $font = $rootDir . $ds . 'source' . $ds . 'font' . $ds . 'simsun.ttc';\n \/\/\u663e\u793a\u7684\u6587\u5b57\n $defaultTxt = $config['default_txt'];\n \/\/\u5c06\u6587\u672c\u5199\u5165\u56fe\u50cf:4\u4e2a\u6570\u5b57\u4f9d\u6b21\u4e3a\uff1a\u5b57\u53f7\uff0c\u65cb\u8f6c\u89d2\u5ea6\uff0cpadding-left,padding-top\n imagefttext($hb, 10, 0, 0, 16, $black, $font, $defaultTxt);\n imagepng($hb);\n }\n imagedestroy($hb);\n}<\/pre>
<\/p>"}