当前位置:Gxlcms > JavaScript > jquery图片水印插件

jquery图片水印插件

时间:2021-07-01 10:21:17 帮助过:65人阅读

简要教程

Img2Blob.js是一款可以为图片添加自定义水印的jquery插件。该jquery图片水印插件可以将图片转换为blob对象,然后为其添加自定义水印效果。

使用方法

在页面中引入jquery和img2blob.js文件。

<script src="path/to/jquery.min.js"></script>
<script src="path/to/img2blob.js"></script>

HTML结构

该自定义图片水印插件的默认效果和水印效果的HTML结构分别如下:

<h3>默认图片</h3>
<img class="sample1" data-img2blob="img/1.png" />
<img class="sample1" data-img2blob="img/2.jpg" />
 
<hr>
 
<h3>添加水印之后的图片</h3>
<img class="sample2" data-img2blob="img/1.png" />
<img class="sample2" data-img2blob="img/2.jpg" />

初始化插件

在页面DOM元素加载完毕之后,可以通过下面的方法来初始化该图片水印插件

$(function() {
 
    // default
    $(".sample1").img2blob();
     
    // with watermark
    $(".sample2").img2blob({
        watermark: '@bachors',
        fontStyle: 'Arial',
        fontSize: '30', // px
        fontColor: '#333', // default 'black'
        fontX: 50, // The x coordinate where to start painting the text
        fontY: 50 // The y coordinate where to start painting the text
    });
 
});

Img2Blob.js图片水印插件的github地址为:https://github.com/bachors/Img2Blob.js

以上就是jquery图片水印插件的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!

人气教程排行