qrcode
The slightly less long-winded not-at-work version of Will

Theme by nostrich.

10th July 2011

Post

“Custom” QR Codes with The Gimp

QR Codes are everywhere now. While these QR codes don’t get you even close to the coolness of something like QRlicious, it’s a start and the beginnings of something to play with.

Create Your Background Image

Obviously, if you want your QR code to look cool, you need to start with a background image. For this example, I’ll start with a screenshot of the script I used to make the QR code itself. (I might publish that script a bit later on - it was super-easy). Some pointers about the image: * Start with something that’s mostly dark without a ton of contrast * It should be square * Depending on what you’re using to produce the QR code, if the image itself is important, you might want to avoid having the subject of the picture go all the way to the edge. My script, for example, does some math to determine how big the blocks of the code must be, then centers them. But if the number of rows or columns plus two doesn’t divide evenly into the number of pixels across, it’ll be centered with padding, which this will turn white.

Here’s the image I’m using. It’s just a screenshot of a simple QR-generating Groovy script opened in MacVim with the Xoria256 color scheme, with a black layer on top at 50% transparency for darkening it.

Original background

Create Your QR Code

I might post my QR-code generating Groovy script later, after a bit of polishing. Or maybe I’ll just make it a Gist on GitHub. But there are lots of sites and libraries for producing your own QR code. The things I’d recommend about it:

  • If you have control over the size, make it the same size as your background image. Not 100% necessary (see the next tip), but will make things a bit easier if it is.
  • Use pure black and white. For the work with the GIMP, we’re going to use a layer mask to make it work, so you need pure black (rgb(0,0,0)) and pure white (rgb(255,255,255)) with no antialiasing. The good news is that if it’s not antialiased, it will scale to whatever size without pixelizing.
  • Depending on the complexity of the URL and the “busy-ness” of the underlying image, you might want to fiddle with the error correction level. The busier your background image, or the more you want to put a slug in the middle of the image, the more important it is to use error correction.

Here’s my QR code: http://will.thestranathans.com

Make the image show through

The next part is where the Gimp comes in. If you have the ridiculous amount of money and know what CMYK stands for and care about CMYK, sure - buy Photoshop. Knock yourself out. You can do all this and a lot of other junk with Photoshop. But this you can do easily with the Gimp and it won’t cost you a red cent beyond the electricity.

  • Open the background image
  • Hit Ctrl-L to open the Layers dialog
  • Double click on the Background text to rename the background layer if you like. (It’s going to be the background, so in my example, it makes sense to leave it as-is).
  • Click the New Layer button New Layer
  • Give the new layer a name (something like QR Code), make the fill White, and hit OK Layer Properties

A bit about layers (forgive me you super image-edity type people)… Layers are a way of putting more image, or more image filters on top of one another. You can turn them on and off, move them about, and edit them individually. There are lots of different “modes” for layers. The most common ones I use are Multiply, where it multiplies the colors on top by the colors beneath to change the color that renders - this is useful for darkening an image, for example; the other is Default, which is kinda’ what you might expect if you had a photograph laying on the table and laid another atop it - you only see the parts of the bottom image that aren’t exposed by the top.

Default is what we’ll use in this case, because we want the color white to cover up the bottom image with blocks where the white will be on our QR code. (You could experiment with tans or other light colors, but for now, just use white).

The next trick we’re going to do is use something called a Layer Mask. A layer mask is a black and white image where the white parts of the layer are kept in the layer, and the black parts are cut out. So the black parts of the mask aren’t kept in the layer at all. It’s not like the underlying image “shines through” the masked parts - the masked parts really aren’t even there. Layer masks are really neat for doing things like cutting a picture of a person out of a background, or doing green-screen effects and such. But with a QR code, since it’s already black and white, it makes making the mask really easy.

  • Right-click the top layer you created, and select Add Layer Mask Add Layer Mask
  • Select White to initialize the layer - this means the whole layer is visible. White Layer Mask
  • Next, you want to make sure that edits you make are made to the layer mask, not to the layer itself. Right click on the Layer Mask, and make sure Edit Layer Mask is ticked. Edit Layer Mask
  • Now, paste the QR code onto the Layer Mask by using Ctrl-V. (Get it on the clipboard by editing it in the Gimp, selecting all, and paste.

If you look in the Layers window, it’ll say “Floating Selection”, but you pasted onto the Layer Mask. So just click the anchor to merge that selection down onto the layer mask. If all goes well, instead of black and white from your QR code, you should see white, but then the background image showing through the black parts. If you use Show Layer Mask, you’ll see just what the mask itself looks like.

Here’s my finished product:

QR Code

by

()