Home Web Front-end H5 Tutorial Pure JS QR code generation plug-in based on canvas

Pure JS QR code generation plug-in based on canvas

Jan 19, 2017 pm 01:44 PM

Brief Tutorial

qrious is a pure JS QR code generation plug-in based on HTML5 Canvas. Various QR codes can be quickly generated through qrious.js. You can control the size and color of the QR code, and you can also Base64 encode the generated QR code.

Installation

You can install the qrious.js QR code plug-in through bower or npm.

$ npm install --save qrious
$ bower install --save qrious
Copy after login

How to use

To use this QR code generation plug-in, you need to introduce the qrious.js file into the page.

<script type="text/javascript" src="js/qrious.js"></script>
Copy after login

HTML structure

Use a element as a container for QR code images.

<canvas id="qr"></canvas>
Copy after login

Initialization plug-in

You can instantiate an object instance through the QRious() method.

(function() {
  const qr = new QRious({
    element: document.getElementById(&#39;qr&#39;),
    value: &#39;http://www.htmleaf.com/&#39;
  })
})()
Copy after login

If you use it in Node.js, the code is as follows:

const express = require(&#39;express&#39;)
const QRious = require(&#39;qrious&#39;)
 
const app = express()
 
app.get(&#39;/qr&#39;, (req, res) => {
  const qr = new QRious({ value: &#39;http://www.htmleaf.com/&#39; })
 
  res.end(new Buffer(qr.toDataURL(), &#39;base64&#39;))
})
 
app.listen(3000)
Copy after login

Configuration parameters

The available configuration parameters of qrious.js QR code plug-in are as follows:

Pure JS QR code generation plug-in based on canvas

For example:

const qr = new QRious()
qr.background = &#39;#000&#39;
qr.foreground = &#39;#fff&#39;
qr.level = &#39;H&#39;
qr.size = 500
qr.value = &#39;http://www.htmleaf.com/&#39;
Copy after login

Or pass it in the constructor:

const qr = new QRious({
  background: &#39;#000&#39;,
  foreground: &#39;#fff&#39;,
  level: &#39;H&#39;,
  size: 500,
  value: &#39;http://www.htmleaf.com/&#39;
})
Copy after login

You can set the QR code used to generate the QR code in the element parameter DOM element. The DOM element must be a element or an Pure JS QR code generation plug-in based on canvas element.

const qr = new QRious({
  element: document.querySelector(&#39;canvas&#39;),
  value: &#39;http://www.htmleaf.com/&#39;
})
 
qr.canvas.parentNode.appendChild(qr.image)
Copy after login

toDataURL([mime]) method

The toDataURL([mime]) method can generate the URI of the Base64 encoded data of the QR code. If you do not specify a MIME Type, the default value will be used as the mime type.

const qr = new QRious({
  value: &#39;http://www.htmleaf.com/&#39;
})
 
console.log(qr.toDataURL())
//=> "data:image/png;base64,iVBOR...AIpqDnseH86KAAAAAElFTkSuQmCC"
console.log(qr.toDataURL(&#39;image/jpeg&#39;))
//=> "data:image/jpeg;base64,/9j/...xqAqIqgKFAAAAAq3RRQAUUUUAf/Z"
Copy after login

The above is the content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
How to create a QR code using wps How to create a QR code using wps Mar 28, 2024 am 09:41 AM

1. Open the software and enter the wps text operation interface. 2. Find the insert option in this interface. 3. Click the Insert option and find the QR code option in its editing tool area. 4. Click the QR code option to pop up the QR code dialog box. 5. Select the text option on the left and enter our information in the text box. 6. On the right side, you can set the shape of the QR code and the color of the QR code.

Recommended: Excellent JS open source face detection and recognition project Recommended: Excellent JS open source face detection and recognition project Apr 03, 2024 am 11:55 AM

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages ​​and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS Dec 17, 2023 pm 06:55 PM

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to create a stock candlestick chart using PHP and JS How to create a stock candlestick chart using PHP and JS Dec 17, 2023 am 08:08 AM

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts Dec 18, 2023 pm 03:39 PM

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

Learn the canvas framework and explain the commonly used canvas framework in detail Learn the canvas framework and explain the commonly used canvas framework in detail Jan 17, 2024 am 11:03 AM

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

What should I do if the QR code on Enterprise WeChat cannot be loaded? What should I do if the QR code on Enterprise WeChat cannot be loaded? Mar 14, 2024 pm 10:46 PM

What should I do if the QR code on Enterprise WeChat cannot be loaded? What should we do when we find that the QR code cannot be loaded and cannot be displayed when logging into the computer version of Enterprise WeChat? Here, the editor will give you a detailed introduction to the solution to the problem that the QR code of Enterprise WeChat cannot be loaded. Anyone who needs it Friends, come and take a look! Method 1. Network reasons 1. The network speed may be slow, resulting in slow loading and failure to display. You can disconnect and reconnect. 2. Check the computer's own network problems to see if it is connected to the network. You can restart the network device. Method 2: Maintenance and update: The QR code may not be generated because the version of Enterprise WeChat is too low. You can upgrade the software to the latest version. Method three, firewall 1

The relationship between js and vue The relationship between js and vue Mar 11, 2024 pm 05:21 PM

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.

See all articles