Code for PHP image watermark

Source: Internet
Author: User
This article mainly introduces the PHP image watermark code, has a certain reference value, now share to everyone, the need for friends can refer to

function she_zhi_shui_ying ($data) {//Picture address $dst _path = str_replace (' Public ', ' storage ', $data->path); Watermark Text $str = $data->mendian_men_dian_ping_pai. ' '. $data->mendian_men_dian_hao. ' '. $data->mendian_name. ' \ n ". Date (" Y-m-d h:i ", Strtotime ($data->xun_kai_si_time)). ' -'. Date ("H:i", Strtotime ($data->xun_jie_shu_time)). " \ n ". $data->created_user_name."        \ n ". $data->canshu_name;                $fileName = $this->wenn_jian_ming_cheng ($dst _path); $path = ' suiying/'. $fileName.        JPG ';        if (Is_file ($path)) {return $path;            }else{//Get picture information $image _info = getimagesize ($dst _path);            Picture height $imageHeight = $image _info[1];            Picture width $imageWidth = $image _info[0];            Create an instance of the picture $dst = Imagecreatefromstring (file_get_contents ($DST _path)); Typing text $font = ' Fonts/msyhbd.ttf ';//font $black = Imagecolorallocatealpha ($DST,255, 255, 255, 63);//Font Color Imagefttext ($dst,, 0,, $imageHeight -80, $black, $font, $STR);            Output Picture List ($dst _w, $dst _h, $dst _type) = getimagesize ($dst _path);                    Switch ($dst _type) {case 1://gif header (' content-type:image/gif ');                    Imagegif ($DST, $path);                Break                    Case 2://jpg//Header (' content-type:image/jpeg ');                    Display//imagejpeg ($DST);                    Save Imagejpeg ($DST, $path);                Break                    Case 3://png Header (' content-type:image/png ');                    Imagepng ($DST, $path);                Break            Default:break;            } Imagedestroy ($DST);        return $path; }    }

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.