Browsed by
Category: PHP

Dynamically generate QR-code using Google Chart Tools

Dynamically generate QR-code using Google Chart Tools

Do you like QR-codes and want to use them on your website? Well, here is some information about how to achieve this. Google has a Chart API which supports generation of QR-codes. By using this API you can dynamically generate your QR-codes.

The following example shows the Hello World QR-code as shown with this post.



The standard base URL for Google Charts is: By adding the needed parameters you can adjust the QR-code:

  • chs=<width>x<height>: Size of the image in pixels
  • cht=qr: The chart type is QR-code
  • chl=<data>: The data to encode. Must be URL-encoded

For more information about the API see

If you are a WordPress user, you can use the following code as an example for adding dynamic QR-codes with each post.

// Use the_permalink() function to dynamically generate the QR-code
src=’<?php the_permalink(); ?>&chs=75×75′

You can add this code anywhere in the index.php of your theme inside the following loop:

<?php while (have_posts()) : the_post(); ?>
<img src=’<?php the_permalink(); ?>&chs=75×75′ />
<?php endwhile; ?>