papnkukn / qrcode-svg Goto Github PK
View Code? Open in Web Editor NEWA simple QR Code generator in pure JavaScript / node.js library
License: MIT License
A simple QR Code generator in pure JavaScript / node.js library
License: MIT License
Hi Everyone,
Hope someone can guide me in the right direction, please.
I am trying to make the SVG 100% width, but it does not work. I have tried the list of options and tried width: 100% in CSS, which works, but the QR code just moves to the center with whitespace on the left and right. It does not show the QR code to scan as 100% width.
I have also tried the width and heights props, but it has the same effect.
Hey, it would be awesome to support micro QR as well as standard QR!
Please add ES6 module support.
Are you still around (the developer)?
I will probably fork and add ES6 module support, would you merge a pull request with ES6 Module support?
Before:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="250" height="250">
<rect x="0" y="0" width="10" height="10" style="fill:#000000;shape-rendering:crispEdges;"/>
<rect x="10" y="0" width="10" height="10" style="fill:#ffffff;shape-rendering:crispEdges;"/>
<rect x="20" y="0" width="10" height="10" style="fill:#000000;shape-rendering:crispEdges;"/>
...
After
<svg xmlns="http://www.w3.org/2000/svg" shape-rendering="crispEdges" viewBox="0 0 250 250">
<defs><path id="c" d="M0 0h10v10H0z"/></defs>
<use x="0" y="0" href="#c"/>
<use x="20" y="0" href="#c"/>
...
My method:
/**
* Output to svg
* @param {number} moduleLength Every modules' length of side
* @return {string} Svg content string
*/
this.toSvg = function(moduleLength) {
var moduleArr = this.qrcode.modules;
var length = moduleArr.length;
var svgContent = '';
var viewBoxLengthStr = length * moduleLength;
svgContent += `<svg xmlns="http://www.w3.org/2000/svg" shape-rendering="crispEdges" viewBox="0 0 ${viewBoxLengthStr} ${viewBoxLengthStr}"><defs><path id="c" d="M0 0h${moduleLength}v${moduleLength}H0z"/></defs>`;
for (var y in moduleArr) {
for (var x in moduleArr) {
var module = moduleArr[x][y];
if (module == true) {
var coordinateX = x * moduleLength;
var coordinateY = y * moduleLength;
svgContent += `<use href="#c" x="${coordinateX}" y="${coordinateY}"/>`;
}
}
}
svgContent += '</svg>';
return svgContent;
};
It is a feature request.
Why on earth would you switch the x and y coordinates? Do you even test your code?
does this library support numeric encoding?
const hello = new QRCode("🖤🌹");
qrcode.js:106 Uncaught Error: code length overflow. (132>128)
at QRCodeModel.createData (qrcode.js:106:47)
at QRCodeModel.makeImpl (qrcode.js:91:26)
at QRCodeModel.getBestMaskPattern (qrcode.js:92:473)
at QRCodeModel.make (qrcode.js:89:101)
Is it possible to encode emojis inside the qrcode?
First, thank you for this so usefull lib.
As for square predefined square template, do you think you could add two others options :
<filter id="blurMe">
<feGaussianBlur in="SourceGraphic" stdDeviation="10" />
</filter>
<circle cx="100"
cy="100"
r="40"
fill="#FFFFFF"
fill-opacity="1.0"
filter="url(#blurMe)"/>
<image xlink:href="data:image/png;base64,iVBzhL15vz+JEAAAAASUVORK5CYII="
x="80"
y="80"
width="50"
height="50"/>
This image inclusion example give something like here
To illustrate my request , you can have a look on Unitag qr generator that provides lot of different angle template and logo inclusion.
hi there! great library. using it in react pdf, which requires us to use its own Svg
and Path
components. it would be useful to have an option to generate just the path of an svg without anything surrounding it. for reference, currently this is my workaround:
const generateQrCodePath = (content: string, size: number) => {
const htmlStr = new QRCode({ content, join: true, width: size, height: size }).svg({container: 'none'});
const parsableHtml = new DOMParser().parseFromString(htmlStr, 'text/html');
return parsableHtml.querySelector('html > body > rect > path')?.getAttribute('d') ?? '';
};
import QRCode from 'qrcode-svg';
...
// in react pdf
return (
<Svg>
<Path d={generateQrCodePath(content, size)} fill='black' />
</Svg>
);
Can you please remove .save()
?
Lines 405 to 420 in 47d56ec
Saving files to disk is very easy in node and the developer can decide wether they need to use sync or async:
fs.writeFileSync("qr.svg", new QRCode("abc").svg());
Hi,
Can you add the function to save the generated QR as PDF or Jpeg
great lib thanks. any good node libraries for reading and parsing svg qr code?
Why there is a default on bgColor? what if i want to lay it on predefined bgs?
We have an issue with our QR code implementation not being detected on certain scanners. It does work on some which is the confusing part.
Not working:
https://qrcoderaptor.com/
https://www.amazon.com/Handsfree-Standard-Scanner-Shielded-DS9208-SR4NNU21Z/dp/B01C65YOE4/ref=sr_1_3?keywords=zebra+symbol+ds9208&qid=1666968387&qu=eyJxc2MiOiIyLjA3IiwicXNhIjoiMi4xNCIsInFzcCI6IjEuOTEifQ%3D%3D&sprefix=zebra+symbol+ds%2Caps%2C83&sr=8-3&ufe=app_do%3Aamzn1.fos.f5122f16-c3e8-4386-bf32-63e904010ad0
Working:
https://www.amazon.com/Desktop-Omnidirectional-Hands-Free-Automatic-Barcodes/dp/B087CSV7NL/?th=1
-Iphones
Things I have tried without success
It would be nice to add the viewBox property in the SVG string.
This make it much easier to scale a single generated SVG using CSS styles.
In my own project, I've solved this in a hacky way by adding viewBox="0 0 250 250"
myself after generating the SVG string.
Lines 88 to 153 in 47d56ec
When requiring this library for browser frontend use, I get this error.
Everything works otherwise, it's just this error showing in the console is annoying.
Lines 312 to 317 in 47d56ec
Please don't do this, for those of us using this library on the web it will break on every sufficiently secured site which doesn't allow script-src 'unsafe-inline'
.
For setting the fill colour, there's a perfectly good fill
attribute you can use instead. For e.g. the crisp edges rendering, please just put the CSS in the README and let us apply it ourselves
QR codes can also be encoded with numeric or alphanumeric encoding for optimal data density. Quoting https://en.wikipedia.org/wiki/QR_code
Input mode | Bits/char. | Possible characters, default encoding |
---|---|---|
Numeric only | 3⅓ | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 |
Alphanumeric | 5½ | 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, : |
Binary/byte | 8 | ISO 8859-1 |
Kanji/kana | 13 | Shift JIS X 0208 |
Is this done automatically in this library? How can I configure what encoding should be used?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.