PHP Text Center (PNG picture compositing)

Source: Internet
Author: User
Tags transparent color png text

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.