qr

by qrcodeenkmmx on February 18th, 2012
No notes
Syntax: XML
Show lines - Hide lines - Show in textbox - Download
  1. <html>
  2. <head>
  3. <title>HTML5 Canvas example</title>
  4. <script type="text/javascript">
  5. window.addEventListener('load', function () {
  6. var element = document.getElementById('myCanvas');
  7. if (!element || !element.getContext) {
  8. return;
  9. }
  10. var context = element.getContext('2d');
  11. if (!context || !context.drawImage) {
  12. return;
  13. }
  14.  
  15. context.fillStyle = '#CC5422'; // set canvas background color
  16. context.fillRect (0, 0, 350, 350); // now fill the canvas
  17.  
  18. context.fillStyle = '#FFFFFF'; // set text color
  19. context.font = 'bold 9px sans-serif'; // set text font
  20. context.textBaseline = 'top'; // set text position
  21. context.fillText ('http://www.kmmx.mx/', 10, 335); // set the text with my blogs URL
  22.  
  23. context.shadowOffsetX = 10; // set x offset for my shadow
  24. context.shadowOffsetY = 10; // set y offset for my shadow
  25. context.shadowBlur = 10; // set blur intensity
  26. context.shadowColor = "black"; // set blur color
  27.  
  28. context.rotate(0.05) // get artsy and rotate context slightly
  29.  
  30.  
  31. // create and draw the google generated qr-code image
  32. var google_img = new Image();
  33. google_img.addEventListener('load', function () {
  34. context.drawImage(this, 35, 25, 275, 275);
  35. },false);
  36. google_img.src = "https://chart.googleapis.com/chart?chs=275x275&cht=qr&chl=http://www.kmmx.mx";
  37.  
  38. // create amd draw the branding image for the qr-code
  39. var branding_img = new Image();
  40. branding_img.addEventListener('load', function () {
  41. context.drawImage(this, 200, -20, 300, 120);
  42. },false);
  43. branding_img.src = "http://kmmx.mx/templates/template_kmmx/images/logo.png";
  44.  
  45. },false);
  46. </script>
  47. </head>
  48.  
  49. <body>
  50. <div style="padding:35px;">
  51. <canvas id="myCanvas" width="430" height="350">
  52. Your browser does not support HTML5 Canvas element.
  53. </canvas>
  54. </div>
  55. </body>
  56. </html>

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS