首页 > 后端开发 > 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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板