> 백엔드 개발 > PHP 튜토리얼 > 图片添加文字水印 和图片水印,添加文字水印图片_PHP教程

图片添加文字水印 和图片水印,添加文字水印图片_PHP教程

WBOY
풀어 주다: 2016-07-13 10:04:35
원래의
1051명이 탐색했습니다.

图片添加文字水印 和图片水印,添加文字水印图片

<?<span>php
    </span><span>/*</span><span>*
     * @desc 图片处理类
     </span><span>*/</span>
     <span>class</span><span> Pic{
        </span><span>private</span> <span>$info</span><span>;
        </span><span>private</span> <span>$res</span><span>;
        </span><span>public</span> <span>$thumb_pic</span><span>;
        </span><span>public</span> <span>function</span> __construct(<span>$picPath</span><span>){
            </span><span>//</span><span>获取图片信息</span>
            <span>$this</span>->info = <span>getimagesize</span>(<span>$picPath</span><span>);
            </span><span>//</span><span>获取图片名</span>
            <span>$this</span>->info['type'] = image_type_to_extension(<span>$this</span>->info[2],<span>false</span><span>);
            </span><span>$funs</span> = 'imagecreatefrom'.<span>$this</span>->info['type'<span>];
            </span><span>$this</span>->res = <span>$funs</span>(<span>$picPath</span><span>);
        }
        </span><span>//</span><span>缩略图</span>
        <span>public</span> <span>function</span> thumb(<span>$w</span>=100,<span>$h</span>=100<span>){
            </span><span>//</span><span>创建图片资源</span>
            <span>$image_thumb</span> = imagecreatetruecolor(<span>$w</span>,<span>$h</span><span>);
            imagecopyresampled(</span><span>$image_thumb</span>,<span>$this</span>->res,0,0,0,0,<span>$w</span>,<span>$h</span>,<span>$this</span>->info[0],<span>$this</span>->info[1<span>]);
            imagedestroy(</span><span>$this</span>-><span>res);
            </span><span>$this</span>->res = <span>$image_thumb</span><span>;
        }

        </span><span>//</span><span>展示</span>
        <span>public</span> <span>function</span><span> showPic(){
            </span><span>header</span>('Content-type:'.<span>$this</span>->info['type'<span>]);
            </span><span>$funs</span> = 'image'.<span>$this</span>->info['type'<span>];
            </span><span>$funs</span>(<span>$this</span>-><span>res);
        
        }
        
        </span><span>//</span><span>保存</span>
        <span>public</span> <span>function</span> savePic(<span>$newname</span><span>){
            </span><span>$funs</span> = 'image'.<span>$this</span>->info['type'<span>];
            </span><span>$funs</span>(<span>$this</span>->res,<span>$newname</span>.".".<span>$this</span>->info['type'<span>]);
        
        
        }
        
        </span><span>//</span><span>销毁图片</span>
        <span>public</span> <span>function</span><span> __destruct(){
            imagedestroy(</span><span>$this</span>-><span>res);
        
        }
        </span><span>/*</span><span>*
         * @desc  添加文字水印
         * @param $content string    文字
         * @param $fonturl string     字体路径
         * @param $fontsize int       字体大小
         * @param $fontcolor array     设置颜色和透明度
         * @param $local array      水印坐标
         * @param $fontangle int    字体旋转角度
         </span><span>*/</span>
        <span>public</span> <span>function</span> fontMark(<span>$content</span>,<span>$fonturl</span>,<span>$fontsize</span>,<span>$fontcolor</span>,<span>$local</span>,<span>$fontangle</span><span>){
            </span><span>$color</span> = imagecolorallocatealpha(<span>$this</span>->res,<span>$fontcolor</span>[0],<span>$fontcolor</span>[1],<span>$fontcolor</span>[2],<span>$fontcolor</span>[3<span>]);
            imagettftext(</span><span>$this</span>->res,<span>$fontsize</span>,<span>$fontangel</span>,<span>$local</span>['x'],<span>$local</span>['y'],<span>$color</span>,<span>$fonturl</span>,<span>$content</span><span>);
        
        }
        </span><span>/*</span><span>*
         * @desc  添加图片水印
         * @param $markPic string 水印图片
         * @param $local array     图片坐标
         * @param $alpha array     设置颜色和透明度
         </span><span>*/</span>
        <span>public</span> <span>function</span> picMark(<span>$markPic</span>,<span>$local</span>,<span>$alpha</span><span>){
            </span><span>$markInfo</span> = <span>getimagesize</span>(<span>$markPic</span><span>);
            </span><span>$markType</span> = image_type_to_extension(<span>$markInfo</span>[2],<span>false</span><span>);
            </span><span>$markFun</span> = 'imagecreatefrom'.<span>$markType</span><span>;
            </span><span>$markWater</span> = <span>$markFun</span>(<span>$markPic</span><span>);
            imagecopymerge(</span><span>$this</span>->res,<span>$markWater</span>,<span>$local</span>['x'],<span>$local</span>['y'],0,0,<span>$markInfo</span>[0],<span>$markInfo</span>[1],<span>$alpha</span><span>);
            imagedestroy(</span><span>$markWater</span><span>);
        
        }
     }
     </span><span>$pic</span> = <span>new</span> Pic('yibo_pic28.jpg'<span>);
     </span><span>$pic</span>->picMark('logo3.png',<span>array</span>('x'=>50,'y'=>50),30<span>);
     </span><span>$pic</span>->showPic();
로그인 후 복사

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/965017.htmlTechArticle图片添加文字水印 和图片水印,添加文字水印图片 ? php /* * * @desc 图片处理类 */ class Pic{ private $info ; private $res ; public $thumb_pic ; public funct...
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿