Header(' Content-type:text/html;charset=utf-8 ');/** * png text composition by Wangzhaobo * @param string $pic _path Picture directory * @param array $text text * @param array $font _file Path * @param array $font _size Text size * @param array $font _pos_y text distance picture Height * @return The name of a string composition picture*/functionSignimg ($pic _path,$text,$font _file,$font _size,$font _pos_y){ //Picture Information List($pic _w,$pic _h,$pic _type) =getimagesize($pic _path); //create an instance of a picture $pic= Imagecreatefrompng ($pic _path); Imagesavealpha ($pic,true);//It is important here to not lose the transparent color of the image; $white= Imagecolorallocate ($pic, 255, 255, 255);//the default text color $yellow= Imagecolorallocate ($pic, 236, 185, 7);//the default text color $font _color= [$white,$yellow,$white,$white]; foreach($text as $key=$value){ $arr= Imagettfbbox ($font _size[$key],0,$font _file[$key],$text[$key]); $text _width=$arr[2]-$arr[0]; Imagefttext ($pic,$font _size[$key], 0, ($pic _w-$text _width)/2,$font _pos_y[$key],$font _color[$key],$font _file[$key],$text[$key]); } //output pictures by canvas type $pngName= Time().Rand(0,9). ". PNG ";//Generate picture name Switch($pic _type) { Case1://GIF Case2://JPG Case3://PNG////Direct output Image Header(' Content-type:image/png '); Imagepng ($pic); //Save Picture Path//Imagepng ($pic, "./assets/sign/". $pngName); return $pngName; Break; default: Break; } Imagedestroy ($pic);} $pic _path= './assets/images/backgroud.png '; $text= [ ' If water and electricity video race goddess tour Chengdu Station ', ' Wang Ruoshui ', ' Spectator time: 2017.9.2 12:30 ', ' Venue: Wanda movie local esports Goddess Tour race (Chengdu station) ' ]; $font _file= [ "./assets/fonts/msyh. TTF ",//Bold Body"./assets/fonts/msyh. TTF ",//Bold Body"./assets/fonts/msyh. TTF ",//Fine Body"./assets/fonts/msyh. TTF "//Fine Body ]; $font _size= [24,42,18,18]; $font _pos_y= [298,470,600,650]; Signimg ($pic _path,$text,$font _file,$font _size,$font _pos_y); //header ("Content-type:image/png"); echo $a;
Material Address: Link: Http://pan.baidu.com/s/1c2vUCAO Password: 3s2i
PHP Text Center (PNG picture compositing)