首頁 > 後端開發 > 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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板