可生成带指定图像效果js二维码插件

可生成带指定图像效果js二维码插件
下载次数:10 文件大小:266.84KB 所需积分:0 QQ联系购买积分:3331653644(1元=10积分)
$(document).ready(function() {
    var value = 'http://www.itshubao.com/';
    var filter = 'threshold';
    var imagePath = 'img/1.jpg';

    var self = this;

    function makeQR() {
        var qr = qrcode.QRCode(10, 'H');
        qr.addData(value);
        qr.make();
        document.getElementById('qr').innerHTML = qr.createImgTag(3);
    }

    function makeQArt() {
        new QArt({
            value: value,
            imagePath: imagePath,
            filter: filter
        }).make(document.getElementById('combine'));
    }

    function getBase64(file, callback) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            callback(reader.result);
        };
    }

    $('#value').keyup(function() {
        value = $(this).val();
        makeQR();
        makeQArt();
    });

    $('#file').change(function() {
        getBase64(this.files[0], function(base64Img) {
            var regex = /data:(.*);base64,(.*)/gm;
            var parts = regex.exec(base64Img);
            imagePath = parts[0];
            $('#image img').attr('src', imagePath);
            makeQArt();
        });
    });

    $('input[type=radio]').click(function() {
        filter = $(this).val();
        makeQArt();
    });

    makeQR();
    makeQArt();
});

 

0 条评论