final app for testing and deployment

This commit is contained in:
2025-07-16 20:45:12 +03:00
parent 729f64f411
commit e9a8f5e622
26 changed files with 1561 additions and 168 deletions

View File

@@ -6,7 +6,9 @@ import os
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers import RoundedModuleDrawer, CircleModuleDrawer, SquareModuleDrawer
from qrcode.image.svg import SvgPathImage, SvgFragmentImage, SvgFillImage
from PIL import Image
import io
class QRCodeGenerator:
def __init__(self):
@@ -19,8 +21,8 @@ class QRCodeGenerator:
'style': 'square'
}
def generate_qr_code(self, data, settings=None):
"""Generate QR code with custom settings"""
def generate_qr_code(self, data, settings=None, format='PNG'):
"""Generate QR code with custom settings in PNG or SVG format"""
if settings is None:
settings = self.default_settings.copy()
else:
@@ -28,6 +30,13 @@ class QRCodeGenerator:
merged_settings.update(settings)
settings = merged_settings
if format.upper() == 'SVG':
return self._generate_svg_qr_code(data, settings)
else:
return self._generate_png_qr_code(data, settings)
def _generate_png_qr_code(self, data, settings):
"""Generate PNG QR code (existing functionality)"""
# Create QR code instance
qr = qrcode.QRCode(
version=1,
@@ -64,6 +73,47 @@ class QRCodeGenerator:
return img
def _generate_svg_qr_code(self, data, settings):
"""Generate SVG QR code"""
# Create QR code instance
qr = qrcode.QRCode(
version=1,
error_correction=settings['error_correction'],
box_size=settings['size'],
border=settings['border'],
)
qr.add_data(data)
qr.make(fit=True)
# Choose SVG image factory based on style
if settings['style'] == 'circle':
# Use SvgFillImage for better circle support
factory = SvgFillImage
else:
# Use SvgPathImage for square and rounded styles
factory = SvgPathImage
# Generate SVG image
img = qr.make_image(
image_factory=factory,
fill_color=settings['foreground_color'],
back_color=settings['background_color']
)
return img
def generate_qr_code_svg_string(self, data, settings=None):
"""Generate QR code as SVG string"""
svg_img = self.generate_qr_code(data, settings, format='SVG')
# Convert SVG image to string
svg_buffer = io.BytesIO()
svg_img.save(svg_buffer)
svg_buffer.seek(0)
return svg_buffer.getvalue().decode('utf-8')
def add_logo(self, qr_img, logo_path, logo_size_ratio=0.2):
"""Add logo to QR code"""
try: