Customized QR Codes with Logos

Categories:

QR codes are all the rage these days, showing up on the side of mass transit buses, advertising flyers, business cards, newspapers, you name it. You’re probably familiar with the stodgy-looking QR code, the one that looks more like it ought to be an inventory label on the side of government cheese than something to catch your eye and give you that inner urge to pull out our iPhone and see what it’s all about. But it doesn’t have to be that way… you can get clever with your QR code and add some customization.

Here at iAchieved.it LLC we’re all about the software, and while sites like Unitag are very handy for one-off QR code creations, we want the ability to programmatically create them. So, even though the ones we present won’t be as fancy as those on the Unitag site, we can set the stage for some creative types to take what we have here and do even more interesting things.

Resolved: We’d like to be able to programmatically generate a QR code with a company logo background. To do so we’ll use two popular tools: qrencode and ImageMagick. In this tutorial we’ll be using our Mac to do the work, but you could substitute in a Linux box, you just have to change up how to get the software installed.

Let’s get qrencode first, and we’ll be using the fantastic Homebrew software on the Mac. If you’ve never used Homebrew there may be some additional steps to get it installed and compiling binaries properly.

$ brew install qrencode
==> Downloading http://fukuchi.org/works/qrencode/qrencode-3.4.3.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/qrencode/3.4.3
==> make
==> make install
/usr/local/Cellar/qrencode/3.4.3: 11 files, 196K, built in 26 seconds

Before we get to creating QR codes with logos, let’s just create a QR code. Pay attention to the options we’re using, because they will actually be important in a moment.

$ qrencode -m 2 -l H "http://dev.iachieved.it/iachievedit/" -o iachievedblog.png

You should get a .png file that looks a little like this.

iachievedblog

Boring. Let’s jazz it up. How about, taking our company logo (no, this really isn’t our company logo, we don’t have enough money for a logo yet) and applying it to our QR Code?

icon_transparent

Enter ImageMagick, one of the most awesome applications out there. We won’t even pretend to know the depth of all the things one can do with the various applications that come with ImageMagick, but rest assured it’s a lot. Enough about that, let’s grab it with Homebrew and put it to use on what we need – and that’s compositing two images.

$ brew install imagemagick
==> Installing imagemagick dependency: freetype
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/freetype-2.5.2.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring freetype-2.5.2.mavericks.bottle.tar.gz
/usr/local/Cellar/freetype/2.5.2: 59 files, 2.7M
==> Installing imagemagick
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/imagemagick-6.8.7-7.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring imagemagick-6.8.7-7.mavericks.bottle.tar.gz
/usr/local/Cellar/imagemagick/6.8.7-7: 1431 files, 20M

Now, let’s take our two images and composite them with (drumroll), the composite command:

composite -blend 100%x100% -gravity center logo.png iachievedblog.png iachievedblog_w_logo.png

The output of this command (the new file iachievedblog_w_logo.png) looks like this:
iachievedblog_w_logo

Hey, not earth-shattering, but more more visually interesting than the plain ol’ code.

Before leaving, let’s revisit the options we gave qrencode and composite. With qrencode the first option -m 2 is for specifying the width of the margins, that is, the width of the whitespace surrounding the QR code. We specified a small width of 2. You can also specify 0 if you want no margin. The more important option we provided though is -l H which specifies a high error correction level. You can read more about the error correction level at QR Stuff, but the upshot is a QR code with a higher error correction level can take “more damage” or, as we like to call it, manipulation.

For composite we specified -blend and -gravity. Our blend is given as 100%x100% which is interpreted as “blend 100% of the first image with 100% of the second image”, mean both images will have equal weight in the output. The second option, -gravity center centers the images together (that is, the logo appears in the center of the code). There are thousands of different combinations that can be specified with composite; to learn more visit the command options page!

Leave a Reply

Your email address will not be published. Required fields are marked *