In this small snippet, I would like to show you how to generate colorized QR-Codes using python:
import qrcode
from qrcode.constants import ERROR_CORRECT_M as ERR_M
qr = qrcode.QRCode( version = 2, error_correction = ERR_M, box_size = 4, border = 2 )
qr.add_data( 'http://www.unimedia-webservice.de' )
qrimg = qr.make_image().convert( 'RGBA' )
pixels = qrimg.load()
for x in range( qrimg.size[0] ):
for y in range( qrimg.size[0] ):
if pixels[x,y] == ( 255, 255, 255, 255 ):
pixels[x,y] = ( 17, 136, 207, 255 ) # RGBA for background
else:
pixels[x,y] = ( 0, 5, 128, 255 ) # RGBA for code
qrimg.show() # or save: qrimg.save( 'qr-code.png', 'PNG' )
The python qrcode library (https://pypi.python.org/pypi/qrcode) is used to generate the QR-Code.
Result
And here is what it looks like: