php图片水印

function she_zhi_shui_ying($data){
        // 图片地址
        $dst_path = str_replace('public', 'storage', $data->path);
        // 水印文字
        $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{  
            // 获取图片信息
            $image_info = getimagesize($dst_path);
            // 图片高度
            $imageHeight = $image_info[1];
            // 图片宽度
            $imageWidth = $image_info[0];

            //创建图片的实例
            $dst = imagecreatefromstring(file_get_contents($dst_path));
            //打上文字
            $font = 'fonts/msyhbd.ttf';//字体
            $black = imagecolorallocatealpha($dst, 255, 255, 255, 63);//字体颜色
            imagefttext($dst, 15, 0, 30, $imageHeight-80, $black, $font, $str);
            //输出图片
            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');
                    // 显示
                    // imagejpeg($dst);
                    // 保存
                    imagejpeg($dst, $path);
                    break;
                case 3://PNG
                    header('Content-Type: image/png');
                    imagepng($dst, $path);
                    break;
                default:
                    break;
            }

            imagedestroy($dst);
            return $path;
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_29755359/article/details/80164452