Created
December 16, 2020 18:49
-
-
Save CSFelix/6e35ddac6d4228ea51134cd517437c68 to your computer and use it in GitHub Desktop.
Revisions
-
CSFelix created this gist
Dec 16, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #!pip install pyqrcode #!pip install pillow import pyqrcode from PIL import Image def NewQRGenerator(string): """ Generates a QR Code and save it in PNG format. How a logo will be insert in the code later, some information will be lost!! In order to prevent it, we use the 'High Redundancy Algorithm' that allows 30% of lost data that the QR Code will still work!!. Assintotic: O(1) """ url = pyqrcode.QRCode(string, error='H') url.png('qr_code.png', scale=10) InsertLogo() def InsertLogo(): """ Insert a logo inside the QR Code and save the changes in PNG format. Assintotic: O(1) """ qr_code = Image.open('qr_code.png') logo = Image.open('python_logo.png') box = (185, 185, 235, 235) # insert position qr_code.crop(box) region = logo region = region.resize((box[2] - box[0], box[3] - box[1])) qr_code.paste(region, box) qr_code.save('qr_code.png') NewQRGenerator("https://csfelix.github.io")