From ea1c2d31fbe556e3e4ecfa6e09e72196b700661b Mon Sep 17 00:00:00 2001 From: cssivision Date: Fri, 21 Aug 2015 14:23:13 +0800 Subject: [PATCH] add logo to qrcode --- src/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/index.js b/src/index.js index 27d1ee2..97299e6 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,7 @@ type Props = { level: $Keys, bgColor: string, fgColor: string, + logo: string, }; class QRCode extends React.Component { @@ -106,6 +107,19 @@ class QRCode extends React.Component { ); }); }); + + if (this.props.logo) { + var size = this.props.size; + var image = document.createElement('img'); + image.src = this.props.logo; + image.onload = function() { + var dx = size / 2 - size * 0.1; + var dwidth = size * 0.2; + if (ctx) { + ctx.drawImage(image, dx, dx, dwidth, dwidth); + } + }; + } } }