Skip to content

xuannghia/qrto

Repository files navigation

QRto - Styled QR Code Generator

Installation

npm install qrto

toSVG

NodeJS/Express

const express = require('express');
const { toSVG } = require('qrto');

const app = express();

app.get('/qr.svg', (req, res) => {
  const svg = toSVG("https://github.com/xuannghia/qrto", {
    style: 'circle',
    marker: {
      style: {
        outer: 'round',
        inner: 'circle',
      }
    },
    // Because of the origin policy
    // the logo URL should be a base64 string or hosted on the same domain as the QR code.
    logo: {
      url: 'data:image/jpeg;base64,/9j/2wCEAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDIBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMv/AABEIAHgAeAMBIgACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APYQtPC04LTwtADQtLtpx4FCDqD1FA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h3FeG/GvZ/EH/HrD/12H8jXkXiH/kKXf8A11/oKAOW06/86+nj8zajbQHIz36/rWtcDVbNSJZWa3PSRG5X39xXLaV/rm/3f6iu81r/AJBZ/wCuX+FAGJbR6pqMzPBaTzkEAtGhxnp16V2Ol6rJpdncabdWn7+J8O8bZ3M2MZz+Az+lL8Pf+PC4/wB4VXv/APkP6n/13g/pQB67Zp5FrFFx8iBTjpwKuKaqpVlaAJM0uaaaWgDB1u1aY7ftxt4gOQFBJP1PNYf9n2//AEF5fzra1/8Aj/3K5qgD/9k=',
    },
    foregroundColor: {
      type: 'linear',
      colors: ['#5271C1', '#0F1E43'],
    },
  })
  res.set('Content-Type', 'image/svg+xml');
  res.send(svg);
});

app.listen(8000, () => {
  console.log('Server is running on port 8000');
});

ReactJS

import React from 'react';

import { toSVG } from 'qrto';

const App = () => {
  const svgString = toSVG("https://github.com/xuannghia/qrto", {
    style: 'circle',
    marker: {
      style: {
        outer: 'round',
        inner: 'circle',
      }
    },
    // Because of the origin policy
    // the logo URL should be a base64 string or hosted on the same domain as the QR code.
    logo: {
      url: 'data:image/jpeg;base64,/9j/2wCEAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDIBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMv/AABEIAHgAeAMBIgACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk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rNghl17xBa2trKYWQ/NKo5C9Wx+VSLukT7KW2vkpn6f/WrpfBmlNa6hc3T7dkUQjUjuScn8eKANW38Jytrdqljds6xESSC4OeAeSCBnNeog1zvhyPdHNeNnMzbV/wB0f/XzXQA0ASA5qG+mmgsLiW3i82ZI2aOP+8wHAqQGnZoA4O68aaxD5sQsI1uYkDvG0LkoD64P1/Ks3/hYOuf8+1t/35f/ABrq7nSbGTWZtSuU3PJEEcOx2YGeo6HgnrSfZPD/APz76b/3wlAG6kylRl1z3571ITWZF/H/ANdP8K0aAFJphNONMPQ0AZet3BiswvXe4X+v9K8R12XUbbUrhIZcK0h3FeG/GvZ/EH/HrD/12H8jXkXiH/kKXf8A11/oKAOW06/86+nj8zajbQHIz36/rWtcDVbNSJZWa3PSRG5X39xXLaV/rm/3f6iu81r/AJBZ/wCuX+FAGJbR6pqMzPBaTzkEAtGhxnp16V2Ol6rJpdncabdWn7+J8O8bZ3M2MZz+Az+lL8Pf+PC4/wB4VXv/APkP6n/13g/pQB67Zp5FrFFx8iBTjpwKuKaqpVlaAJM0uaaaWgDB1u1aY7ftxt4gOQFBJP1PNYf9n2//AEF5fzra1/8Aj/3K5qgD/9k=',
    },
    foregroundColor: {
      type: 'linear',
      colors: ['#5271C1', '#0F1E43'],
    },
  })

  // Because toSVG just return a raw string
  // So we need to use `dangerouslySetInnerHTML` to render it as SVG Element
  return <div dangerouslySetInnerHTML={{ __html: svgString }} />
}

toCanvas

Coming soon...

About

Generate styled QRCode in any JS runtime

Resources

Stars

Watchers

Forks