Image credit: Mitya Ivanov/Unsplash
Two-dimensional (2D) barcodes, more prominently recognized as QR codes, are back in fashion—with much demand for just about ‘contactless’ everything these days.
Coinbase didn’t waste time in seizing this opportunity either: its genius Superbowl 2022 TV ad was nothing but a mysterious QR code against a pitch-black background aimed at capturing your attention totally.
Even those who may not understand how exactly these quirky-looking squares work have pretty much used them at some point.
But, is there such a thing as moving or animated QR codes? And could they work?
Scan it for yourselves.
This week, technologist, “cyborg hardware hacker,” and YouTuber, Zack Freedman tweeted a GIF that’s gone viral.
The GIF shown below contains an animated QR code with moving frames that some might recognize—a sequence from Rick Astley’s famous Never Gonna Give You Up music video.
Lyrics from the song and the music video itself have been a popular meme for the longest time used by netizens and even malicious actors trolling hacked companies.
But, other than being an artistic barcode, Freedman’s GIF actually works as a QR code: scan it for yourselves!
Assuming your QR code scanner app works, the above GIF will lead you to the official Never Gonna Give You Up music video on YouTube.
In fact, there exist online tools, like the one created by QR4 and software engineer Jeroen Steeman, allowing you to create your own animated QR codes!
Diving deeper into barcodes
The origins of barcodes date back to the 1950s when two graduate students at Drexel University (ahem, my alma mater) patented a system for easy cataloging and looking up of electronic product information.
What may have originally started out as an inventory-tracking concept, however, evolved in terms of complexity, available formats, and even dimensions, with the advent of 2D barcodes.
Commonly known as QR (Quick Response) codes, these matrices are just one type of 2D barcodes, invented in 1994 by Japanese automotive firm Denso Wave, which still holds the trademark to the term ‘QR Code’ and even a patent on the technology.
While one-dimensional barcodes, like the UPCs you see on book covers and merchandise, are capable of holding simple one-liner strings—such as an SKU, item number, or another set of characters up to a certain length (around 85 characters), 2D barcodes are far more versatile in their capacity to hold data, the ability to hold different types of data, and various error checking and correction mechanisms built into them.
2D barcodes, as the name implies, have multiple dimensions and can store data across the entire matrix, as opposed to just a single line (dimension). And each part of the QR code matrix has a special meaning and role to play, with the content-holding section being just one part of the entire matrix.
The error checking and correction aspects of 2D barcodes are important in the sense, that even if parts of the QR code are cut off or corrupted, the QR code may still continue to scan correctly and retain the content stored inside it. Try it for yourself:
This isn’t the case for 1D barcodes—these work by the scanner calculating the ratio of widths of straight bars next to each other. And as such, if you cover up or destroy a part of the 1D barcode, it may not scan correctly.
But, the very error correction mechanism built into QR codes allows barcode creators to get creative: to pack functional content (such as a URL or another piece of data) in a small part of the entire matrix, with other parts of the matrix serving essentially as a blank canvas for artistic imagery:
This explains why artistic barcodes, like the one shown above, or the panther QR code GIF in the beginning may continue to scan correctly: the areas of the QR code containing the functional data (URL) are a smaller part of the entire matrix.
In the case of the panther GIF above, the pixels (and hence areas of QR code) around the moving panther are relatively static, and this is where the content might be present, rather than the center where the animation plays.
But, what’s going on in Freedman’s GIF appears to be a tad more complicated. Each frame of the GIF changes the QR code almost entirely, with pixels rearranging themselves.
For those well-versed in computer vision, Twitter user and tech blogger BenBE may have an answer for you:
Sampling: There’s actually 3×3 pixel subdivisions for each of the large pixels. Processing only cares about the middle pixels, thus that’s where the data is.
The middle pixel is sometimes changed to fit the dithering, so the actually “raw” encoded QR code changes over time.
— BenBE (@BenBE1987) April 22, 2022
For every little square in Freedman’s blockbuster (pun) QR code, your scanner is only looking at the middle of each such square (that comprises 3×3 or 9 pixels in total). As such, it is within these pixels that the content part of the barcode (the YouTube URL) is stored, with the rest of the pixels serving as a blank canvas, used for animation.
Those who prefer to read more about ‘dithering’ and the many possibilities it offers, might be interested in revisiting a two-year-old YCombinator Hacker News thread.
The generator enables you to create fully-functional QR codes that look like real pictures as much as possible and even animate them to your liking.