lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.34k stars 664 forks source link

Consider adding/extending module_drawer for SVG output? #248

Closed GregoryHarrison closed 2 years ago

GregoryHarrison commented 2 years ago

I have extended the default moduledrawers.py to add a SpriteModuleDrawer (requires import math):

class SpriteModuleDrawer(QRModuleDrawer):
    """
    Draws the modules as small circles (sprites)
    """
    circle = None
    def initialize(self, styledPilImage, image):
        box_size = styledPilImage.box_size
        fake_size = box_size * ANTIALIASING_FACTOR
        sprite_size = math.ceil(fake_size / 1.6)
        self.circle = Image.new(styledPilImage.mode,(fake_size, fake_size), styledPilImage.color_mask.back_color)
        ImageDraw.Draw(self.circle).ellipse((0,0, sprite_size, sprite_size), fill = styledPilImage.paint_color)
        self.circle = self.circle.resize((box_size, box_size), Image.LANCZOS)
        self.image = image
    def drawrect_context(self, box, is_active, context):
        if is_active:
            self.image.paste(self.circle, (box[0][0], box[0][1]))

image

I am unclear on if/how such custom moduledrawers can be applied to SVG output?