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; } }