Custom logos

This commit is contained in:
alex
2024-10-16 17:08:25 +02:00
parent e590e65a4b
commit 0e23a8bb65
2 changed files with 9 additions and 4 deletions

11
main.py
View File

@@ -14,8 +14,13 @@ from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer
default="./qrcode.png", default="./qrcode.png",
help='Output file path (defaults to "./qrcode.png")', help='Output file path (defaults to "./qrcode.png")',
) )
@click.option(
"--logo_path",
default=None,
help='Path to the logo to to embed (defaults to the Canonical one)',
)
@click.argument("url") @click.argument("url")
def create(output_file, url): def create(output_file,logo_path, url):
qr = qrcode.QRCode( qr = qrcode.QRCode(
version=1, version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H, error_correction=qrcode.constants.ERROR_CORRECT_H,
@@ -24,14 +29,14 @@ def create(output_file, url):
) )
qr.add_data(url) qr.add_data(url)
qr.make(fit=True) qr.make(fit=True)
logo=logo_path if logo_path else f"{os.environ.get("SNAP")}/assets/canonical.png"
qri = qr.make_image( qri = qr.make_image(
image_factory=StyledPilImage, image_factory=StyledPilImage,
color_mask=SolidFillColorMask( color_mask=SolidFillColorMask(
back_color=(255, 255, 255), front_color=(233, 84, 32) back_color=(255, 255, 255), front_color=(233, 84, 32)
), ),
module_drawer=RoundedModuleDrawer(), module_drawer=RoundedModuleDrawer(),
embeded_image_path=f"{os.environ.get("SNAP")}/assets/canonical.png", embeded_image_path=logo,
) )
qri.save(output_file) qri.save(output_file)

View File

@@ -1,6 +1,6 @@
name: cqrcode # you probably want to 'snapcraft register <name>' name: cqrcode # you probably want to 'snapcraft register <name>'
base: core24 # the base snap is the execution environment for this snap base: core24 # the base snap is the execution environment for this snap
version: '1.0' # just for humans, typically '1.2+git' or '1.3.2' version: '1.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: Create QR codes flying Canonical colors. # 79 char long summary summary: Create QR codes flying Canonical colors. # 79 char long summary
description: | description: |
TODO TODO