-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
venv |
Binary file not shown.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pathlib | ||
import argparse | ||
from PIL import Image, ImageDraw, ImageFont | ||
|
||
import qrcode | ||
|
||
|
||
MENU_TYPES = { | ||
"Drinks": ("Boissons", 310, 90), | ||
"Snacks": ("Snacks", 250, 90), | ||
} | ||
|
||
|
||
def generate_text_image(text, width, height): | ||
img = Image.new("RGB", (width, height), color = (255, 255, 255)) | ||
d = ImageDraw.Draw(img) | ||
font = ImageFont.truetype("Roboto-Bold.ttf", 70) | ||
d.text((10, 5), text, fill=(0, 0, 0), font=font) | ||
return img | ||
|
||
|
||
def generate_qr_code(uri, text): | ||
qr_code = qrcode.QRCode(version=None, error_correction=qrcode.constants.ERROR_CORRECT_M, border=4, box_size=20) | ||
qr_code.add_data(uri) | ||
qr_code.make() | ||
qr_img = qr_code.make_image() | ||
height = 40 if text else 0 | ||
final_img = Image.new("RGB", (qr_img.size[0], qr_img.size[1] + height), (255, 255, 255)) | ||
final_img.paste(qr_img, (0, height)) | ||
|
||
if text: | ||
text_img = generate_text_image(*MENU_TYPES[text]) | ||
x = qr_img.size[0] / 2 - text_img.size[0] / 2 | ||
final_img.paste(text_img, (int(x), 10)) | ||
|
||
return final_img | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument("uri") | ||
parser.add_argument("-o", "--output", type=pathlib.Path, default="qrcode.png") | ||
parser.add_argument("-t", "--text", type=str, choices=["Snacks", "Drinks", None], required=True) | ||
|
||
args = parser.parse_args() | ||
img = generate_qr_code(args.uri, args.text) | ||
img.save(args.output) | ||
|
||
img = generate_text_image(*MENU_TYPES["Snacks"]) | ||
img.save("a.png") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Pillow==8.2.0 | ||
qrcode==6.1 | ||
six==1.16.0 |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
https://github.com/Max-7/marquise/blob/master/drinks.pdf?raw=true | ||
https://github.com/Max-7/marquise/blob/master/snacks.png?raw=true |