• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    QR Code Generator Base (gallery-qr-code-generator-base) on cdn

    Last Updated: 06/23/12
    + 0 -

    Steven Olmsted

    YUI Contributor

    See 42 more by this user.

    Created: 03/20/12
    Last CDN Push: 06/20/12
    Build Tag: gallery-2012.06.20-20-07
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.5.1
    Free for use.

    Y.QrCode.GeneratorBase is a slightly low-level utility for generating QR Codes. I'm calling it low-level for two primary reasons.

    1: QR Codes have different data encoding modes. The source data can be split up into smaller chunks and each chunk can be encoded in a different mode. A complete QR Code generator should be able to analyse any given input data and optimize it by splitting it into different mode chunks such that the data can be encoded into the smallest space possible. Y.QrCode.GeneratorBase does not do any such analysis; data can be given as one or more chunks, but the data will be encoded as is.

    2: Y.QrCode.GeneratorBase returns an array of boolean values. This array represents the light and dark pixels of a QR Code image. Extra steps are necessary to render the data.

    Y.QrCode.GeneratorBase is intended to be extended to implement this higher level functionality.

    That being said, Y.QrCode.GeneratorBase can be used by itself to generate QR Codes.

    • Tags:
    • barcode
    • solmsted
    • qr
    • code
    • 2d
    • generator
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Input data must be wrapped up in data objects. Currently, three data modes are supported.

    NumericData encodes strings containing only numeric characters: 0123456789
    AlphanumericData encodes strings containing only numeric characters, capital-letter characters, space, dollar sign, percent sign, asterisk, plus sign, hyphen-minus, full stop, solidus, and colon: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:
    ByteData encodes strings as raw binary data.

    Other data modes are planned to be added in the future.

    There are 40 different versions of QR Codes. A QR Code's version is just a confusing way to specify how big it is. A version 1 QR Code is a 25x25 grid. That size increases by 4 up to the 181x181 grid of a version 40 QR code. The larger the grid, the more data the QR Code can hold.

    QR Codes use error correction when encoding data. Error correction allows a code to be successfully scanned even if part of the code is damaged, missing, or scanned incorrectly. There are four different error correction modes. Mode H can recover from 30% data loss. Mode L can recover from 7% data loss. Mode M can recover from 15% data loss. Mode Q can recover from 25% data loss. The more error correction added, the less data the QR Code can hold.

    If there is too much data for the specified version and error correction mode, Y.QrCode.GeneratorBase will return an error.

    Code Sample

    <script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2012.06.20-20-07'
    }).use('gallery-qr-code-generator-base', function(Y) {
        var generator = new Y.QrCode.GeneratorBase({
            data: new Y.QrCode.NumericData({
                value: '01234567'
            }),
            errorCorrection: 'Q',
            version: '2'
        });
     
        generator.generate(function (error, matrix, size) {
            if (error) {
                // If defined, error is a string containing an error message.
                alert(error);
                return;
            }
     
            var pixelValue,
                x,
                y;
     
            for (y = 0; y < size; y += 1) {
                for (x = 0; x < size; x += 1) {
                    pixelValue = matrix[x + y * size];
                    // pixelValue will be true or false.
                    // true represents a dark pixel; false represents a light pixel.
                    // TODO: Do something to render pixelValue somewhere.
                }
            }
        });
    });

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info