>  기사  >  백엔드 개발  >  PHP 이미지 워터마크 코드

PHP 이미지 워터마크 코드

不言
不言원래의
2018-05-02 12:49:411648검색

이 글은 주로 참고할 가치가 있는 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;
        }
    }

관련 추천:

PHP 이메일로 보내기

PHP


의 데이터 유형

위 내용은 PHP 이미지 워터마크 코드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.