### run_example function example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example usage of the run_example function. ```python import qrcode # Display example in default viewer qrcode.run_example('https://github.com') # With options qrcode.run_example('Custom data', error_correction=qrcode.ERROR_CORRECT_H) ``` -------------------------------- ### CircleModuleDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating how to use the CircleModuleDrawer. ```python from qrcode.image.styles.moduledrawers.pil import CircleModuleDrawer img = qr.make_image(module_drawer=CircleModuleDrawer()) img.save('circles.png') ``` -------------------------------- ### best_fit() method examples Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Examples of automatically determining the minimum QR code version needed for the data, including starting the search from a specific version. ```python qr = qrcode.QRCode() qr.add_data('Find smallest version') # Automatically find best version best_version = qr.best_fit() print(f'Minimum version needed: {best_version}') ``` ```python # Can also start search from a specific version best_version = qr.best_fit(start=5) ``` -------------------------------- ### version property example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Examples of getting the current QR code version and explicitly setting it. ```python qr = qrcode.QRCode() print(qr.version) # Triggers best_fit() if not set ``` ```python qr.version = 5 # Explicitly set version ``` -------------------------------- ### SquareModuleDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating how to use the SquareModuleDrawer with StyledPilImage. ```python import qrcode from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers.pil import SquareModuleDrawer qr = qrcode.QRCode(image_factory=StyledPilImage) qr.add_data('Squares') qr.make() img = qr.make_image(module_drawer=SquareModuleDrawer()) img.save('squares.png') ``` -------------------------------- ### mask_func Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Shows how to get and apply a mask function for a specific mask pattern. ```python from qrcode.util import mask_func # Get mask function for pattern 3 mask = mask_func(3) # Apply to coordinates is_masked = mask(5, 10) # True or False # Use to apply mask to modules for row in range(size): for col in range(size): if mask(row, col): modules[row][col] = not modules[row][col] # Invert ``` -------------------------------- ### make function example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example usage of the make function. ```python import qrcode # Quick one-liner img = qrcode.make('Hello World') img.save('quick_qr.png') # With options img = qrcode.make( 'URL to encode', version=1, error_correction=qrcode.ERROR_CORRECT_H, box_size=15, border=2 ) img.save('formatted_qr.png') ``` -------------------------------- ### optimal_data_chunks Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Example demonstrating how to split data into optimized chunks. ```python from qrcode.util import optimal_data_chunks, MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE data = "HELLO123WORLD456" # Automatic optimization (splits into efficient chunks) chunks = list(optimal_data_chunks(data, minimum=4)) for chunk in chunks: print(f"Mode: {chunk.mode}, Data: {chunk.data}") # Disable optimization chunks_unoptimized = list(optimal_data_chunks(data, minimum=0)) # Returns single chunk in MODE_8BIT_BYTE # With minimum size chunks_large = list(optimal_data_chunks("ABC1234D", minimum=5)) # "1234" is only 4 digits, won't be optimized ``` -------------------------------- ### ActiveWithNeighbors Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example demonstrating how to get and use the ActiveWithNeighbors context for a module. ```python from qrcode.main import QRCode r = QRCode() r.add_data('Neighbors') r.make() # Get context for a module context = qr.active_with_neighbors(5, 5) print(f"Module at (5,5) is dark: {context.me}") print(f"Has dark neighbor to the north: {context.N}") print(f"Has dark neighbor to the south: {context.S}") # Use in boolean context if context: print("Module is active (dark)") else: print("Module is inactive (light)") ``` -------------------------------- ### GappedCircleModuleDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating how to use the GappedCircleModuleDrawer. ```python from qrcode.image.styles.moduledrawers.pil import GappedCircleModuleDrawer img = qr.make_image(module_drawer=GappedCircleModuleDrawer()) img.save('gapped_circles.png') ``` -------------------------------- ### __len__() Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Example demonstrating the usage of the __len__() method. ```python data = QRData('Hello') print(len(data)) # 5 # For numeric mode, length is different numeric = QRData('123456789') print(len(numeric.data)) # 9 (bytes) ``` -------------------------------- ### Example SVG Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Examples of using different SVG drawers and custom attributes. ```python from qrcode.image.svg import SvgImage # Circle modules img = qr.make_image( image_factory=SvgImage, module_drawer="circle" ) # Gapped circles img = qr.make_image( image_factory=SvgImage, module_drawer="gapped-circle" ) # Custom SVG attributes img = qr.make_image( image_factory=SvgImage, attrib={'class': 'qrcode', 'id': 'main-qr'} ) ``` -------------------------------- ### Standard Install Source: https://github.com/lincolnloop/python-qrcode/blob/main/README.rst Installs the qrcode library with default PNG generation capabilities. ```bash pip install qrcode ``` -------------------------------- ### make Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Examples of auto-fitting to the smallest version and using a specific version without fitting. ```python qr = qrcode.QRCode(version=5) qr.add_data('Test') # Auto-fit to smallest version that fits data qr.make(fit=True) # Use specific version without fitting qr2 = qrcode.QRCode(version=10) qr2.add_data('Test') qr2.make(fit=False) # Uses version 10 regardless ``` -------------------------------- ### optimal_mode Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Example demonstrating how to determine the optimal encoding mode for data. ```python from qrcode.util import optimal_mode, MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE assert optimal_mode(b'12345') == MODE_NUMBER assert optimal_mode(b'HELLO WORLD') == MODE_ALPHA_NUM assert optimal_mode(b'hello') == MODE_8BIT_BYTE # lowercase assert optimal_mode(b'\x00\x01') == MODE_8BIT_BYTE # binary ``` -------------------------------- ### Color Format Examples (PilImage) Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Examples of different color formats for fill_color and back_color with PilImage. ```python # Named colors (if PIL supports them) img = qr.make_image(fill_color="darkblue", back_color="yellow") # RGB tuples (0-255 each) img = qr.make_image(fill_color=(0, 0, 255), back_color=(255, 255, 255)) # RGBA tuples (with alpha channel) img = qr.make_image( fill_color=(0, 0, 255, 255), # opaque blue back_color=(255, 255, 255, 128) # semi-transparent white ) # Transparent background img = qr.make_image(back_color="transparent") ``` -------------------------------- ### GappedSquareModuleDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating how to use the GappedSquareModuleDrawer with a specified size ratio. ```python from qrcode.image.styles.moduledrawers.pil import GappedSquareModuleDrawer img = qr.make_image(module_drawer=GappedSquareModuleDrawer(size_ratio=0.6)) img.save('gapped_squares.png') ``` -------------------------------- ### run_example function Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Build and display an example QR code in the default image viewer. ```python def run_example(data="http://www.lincolnloop.com", *args, **kwargs): ``` -------------------------------- ### Sample example to generate QR code Source: https://github.com/lincolnloop/python-qrcode/wiki/Home Generates a QR code and saves it to a file. ```python import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('Some data') qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") img.save('abc.png') ``` -------------------------------- ### StyledPilImage Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md A complete example demonstrating how to create a styled QR code with a gapped module drawer, horizontal gradient color mask, and an embedded image. ```Python import qrcode from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers.pil import GappedSquareModuleDrawer from qrcode.image.styles.colormasks import HorizontalGradiantColorMask qr = qrcode.QRCode( error_correction=qrcode.ERROR_CORRECT_H, image_factory=StyledPilImage ) qr.add_data('Styled QR') qr.make() img = qr.make_image( module_drawer=GappedSquareModuleDrawer(size_ratio=0.7), color_mask=HorizontalGradiantColorMask( left_color=(255, 0, 0), right_color=(0, 0, 255) ), embedded_image_path='logo.png', embedded_image_ratio=0.3 ) img.save('styled_logo.png') ``` -------------------------------- ### Install with PIL support Source: https://github.com/lincolnloop/python-qrcode/blob/main/README.rst Installs the qrcode library with Pillow support for more image functionality. ```bash pip install "qrcode[pil]" ``` -------------------------------- ### Minimal Configuration Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example of using all default settings for the QRCode constructor. ```python import qrcode # Use all defaults qr = qrcode.QRCode() qr.add_data('Hello') qr.make() img = qr.make_image() ``` -------------------------------- ### pattern_position Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Illustrates how to get the alignment pattern positions for a given QR code version. ```python from qrcode.util import pattern_position # Version 1 has no alignment patterns positions_v1 = pattern_position(1) # [] # Version 2 has alignment patterns positions_v2 = pattern_position(2) # [6, 18] # Version 7 has multiple alignment patterns positions_v7 = pattern_position(7) # [6, 22, 38] # Version 40 (largest) positions_v40 = pattern_position(40) ``` -------------------------------- ### make_image Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example of creating an image from compiled QR code data. ```python qr = qrcode.QRCode() qr.add_data('Example') qr.make() ``` -------------------------------- ### ImportError: pypng not installed Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/errors.md Example of catching an ImportError when pypng is not installed. ```python ImportError("PyPNG library not installed.") ``` ```python from qrcode.image.pure import PyPNGImage try: img = qrcode.make('Test', image_factory=PyPNGImage) except ImportError: print("pypng is required for pure Python PNG support") print("Install with: pip install pypng") ``` -------------------------------- ### add_data Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Examples of adding string data, bytes, multiple calls, and disabling optimization. ```python qr = qrcode.QRCode() # Add string data qr.add_data('Hello World') # Add bytes qr.add_data(b'Binary data') # Multiple calls append data qr.add_data('More data') # Disable optimization qr.add_data('12345', optimize=0) ``` -------------------------------- ### HorizontalBarsDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example of creating a QR code image using the HorizontalBarsDrawer. ```python from qrcode.image.styles.moduledrawers.pil import HorizontalBarsDrawer img = qr.make_image(module_drawer=HorizontalBarsDrawer()) img.save('horizontal_bars.png') ``` -------------------------------- ### best_mask_pattern() method example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example showing how best_mask_pattern() is called internally by make() when mask_pattern is None. ```python qr = qrcode.QRCode(mask_pattern=None) # Auto-select best qr.add_data('Optimize pattern') qr.make() # best_mask_pattern() is called internally by make() ``` -------------------------------- ### make() Options Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example demonstrating the fit parameter in make() for auto-fitting the QR code version or using a fixed version. ```Python qr.make(fit=True) ``` ```Python # Auto-fit (recommended for most use cases) qr = qrcode.QRCode() qr.add_data('Data') qr.make(fit=True) # Finds smallest version that fits # Fixed size qr = qrcode.QRCode(version=5) qr.add_data('Data') qr.make(fit=False) # Uses version 5, raises DataOverflowError if too small ``` -------------------------------- ### SvgPathSquareDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example of creating a QR code image using SvgPathSquareDrawer with SvgPathImage factory. ```python from qrcode.image.svg import SvgPathImage img = qrcode.make( 'SVG Path Squares', image_factory=SvgPathImage, module_drawer='gapped-square' ) img.save('path_squares.svg') ``` -------------------------------- ### VerticalBarsDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example of creating a QR code image using the VerticalBarsDrawer. ```python from qrcode.image.styles.moduledrawers.pil import VerticalBarsDrawer img = qr.make_image(module_drawer=VerticalBarsDrawer(horizontal_shrink=0.7)) img.save('vertical_bars.png') ``` -------------------------------- ### Get ASCII text content from print_ascii Source: https://github.com/lincolnloop/python-qrcode/blob/main/README.rst Example of capturing the ASCII output from the print_ascii method. ```python import io import qrcode qr = qrcode.QRCode() qr.add_data("Some text") f = io.StringIO() qr.print_ascii(out=f) f.seek(0) print(f.read()) ``` -------------------------------- ### SvgImage example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of creating a standalone SVG image. ```python from qrcode.image.svg import SvgImage img = qrcode.make('SVG', image_factory=SvgImage) img.save('standalone.svg') ``` -------------------------------- ### DrawerAliases Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example of how to use DrawerAliases with qrcode.make(). ```python from qrcode.image.svg import SvgImage # Access available aliases alias = SvgImage.drawer_aliases # { # "circle": (SvgCircleDrawer, {}), # "gapped-circle": (SvgCircleDrawer, {"size_ratio": Decimal("0.8")}), # "gapped-square": (SvgSquareDrawer, {"size_ratio": Decimal("0.8")}), # } # Use with qrcode.make() img = qrcode.make('SVG', image_factory=SvgImage, module_drawer='circle') ``` -------------------------------- ### SvgPathCircleDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example of creating a QR code image using SvgPathCircleDrawer with SvgPathImage factory. ```python from qrcode.image.svg import SvgPathImage img = qrcode.make( 'SVG Path Circles', image_factory=SvgPathImage, module_drawer='circle' ) img.save('path_circles.svg') ``` -------------------------------- ### BaseImage pixel_box Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of using the pixel_box method. ```python img = qr.make_image() box = img.pixel_box(0, 0) # Top-left module # Returns ((x, y), (x + box_size - 1, y + box_size - 1)) ``` -------------------------------- ### PyPNGImage Example Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of creating a QR code using PyPNGImage. ```python from qrcode.image.pure import PyPNGImage img = qrcode.make('Pure PNG', image_factory=PyPNGImage) img.save('output.png') ``` -------------------------------- ### Basic Console Script Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example of using the `qr` command-line tool with specific options. ```bash qr --factory=svg-path --error-correction=H --ascii "Data" ``` -------------------------------- ### SvgSquareDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example of creating a QR code image using SvgSquareDrawer with SvgImage factory. ```python from qrcode.image.svg import SvgImage from qrcode.image.styles.moduledrawers.svg import SvgSquareDrawer img = qrcode.make( 'SVG Squares', image_factory=SvgImage, module_drawer=SvgSquareDrawer() ) img.save('svg_squares.svg') # Or use string alias img = qrcode.make( 'SVG', image_factory=SvgImage, module_drawer='gapped-square' ) ``` -------------------------------- ### StyledPilImage Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example usage of StyledPilImage with custom drawers, color masks, and embedded images. ```python import qrcode from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer from qrcode.image.styles.colormasks import RadialGradiantColorMask qr = qrcode.QRCode( error_correction=qrcode.ERROR_CORRECT_H, image_factory=StyledPilImage ) qr.add_data('Styled QR') qr.make() # Create with rounded corners and radial gradient img = qr.make_image( module_drawer=RoundedModuleDrawer(), color_mask=RadialGradiantColorMask() ) img.save('styled.png') # With embedded image img = qr.make_image( embedded_image_path='/path/to/logo.png', embedded_image_ratio=0.3 ) img.save('with_logo.png') ``` -------------------------------- ### SvgImage Drawer Alias Usage Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating the usage of string aliases for SvgImage drawers. ```python # String alias img = qrcode.make('SVG', image_factory=SvgImage, module_drawer='circle') # Equivalent to: from qrcode.image.styles.moduledrawers.svg import SvgCircleDrawer img = qrcode.make('SVG', image_factory=SvgImage, module_drawer=SvgCircleDrawer()) ``` -------------------------------- ### QRCode Constructor Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Basic usage with default settings and advanced usage with custom settings. ```python import qrcode # Basic usage with default settings qr = qrcode.QRCode() qr.add_data('https://example.com') qr.make() img = qr.make_image() img.save('qrcode.png') # Advanced usage with custom settings qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_H, box_size=15, border=2, ) qr.add_data('Custom QR Code') qr.make(fit=True) img = qr.make_image(fill_color="blue", back_color="white") img.save('custom_qr.png') ``` -------------------------------- ### BaseImage is_eye Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of using the is_eye method. ```python # Used internally by styled image factories to apply different styling to eyes is_in_eye = img.is_eye(row, col) ``` -------------------------------- ### SvgPathImage example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Examples of creating SVG path images with default and custom drawers. ```python from qrcode.image.svg import SvgPathImage # Default square path img = qrcode.make('Path SVG', image_factory=SvgPathImage) img.save('path.svg') # Circular modules img = qrcode.make( 'Circular Paths', image_factory=SvgPathImage, module_drawer='circle' ) img.save('circles.svg') ``` -------------------------------- ### to_bytestring Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Example demonstrating the conversion of data to UTF-8 encoded bytes. ```python from qrcode.util import to_bytestring # Already bytes assert to_bytestring(b'bytes') == b'bytes' # String to UTF-8 assert to_bytestring('hello') == b'hello' # Unicode characters emoji_bytes = to_bytestring('Hello 👋') assert emoji_bytes == 'Hello 👋'.encode('utf-8') ``` -------------------------------- ### RoundedModuleDrawer Example (Subtle Rounding) Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating RoundedModuleDrawer with subtle rounding (radius_ratio=0.3). ```python from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer # Subtle rounding img = qr.make_image(module_drawer=RoundedModuleDrawer(radius_ratio=0.3)) img.save('rounded_subtle.png') ``` -------------------------------- ### Context-Aware Drawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md An example of a context-aware drawer that uses neighbor information to adjust drawing. ```python from qrcode.image.styles.moduledrawers.pil import StyledPilQRModuleDrawer from qrcode.main import ActiveWithNeighbors class ContextAwareDrawer(StyledPilQRModuleDrawer): needs_neighbors = True def drawrect(self, box, is_active: ActiveWithNeighbors): if not is_active.me: return # Check neighbors if is_active.N and is_active.S: # Has vertical neighbors, draw vertically stretched pass elif is_active.E and is_active.W: # Has horizontal neighbors, draw horizontally stretched pass else: # Isolated module pass ``` -------------------------------- ### PilImage save Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of saving a PNG image using PilImage. ```python img = qrcode.make('PNG Test') # Save to file img.save('output.png') # Save to file-like object import io buffer = io.BytesIO() img.save(buffer, format='PNG') # Save as JPEG img.save('output.jpg', format='JPEG') ``` -------------------------------- ### mode_sizes_for_version Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Shows how to retrieve encoding mode sizes for different QR code versions. ```python from qrcode.util import mode_sizes_for_version sizes_v1 = mode_sizes_for_version(1) # Returns MODE_SIZE_SMALL sizes_v15 = mode_sizes_for_version(15) # Returns MODE_SIZE_MEDIUM sizes_v30 = mode_sizes_for_version(30) # Returns MODE_SIZE_LARGE ``` -------------------------------- ### StyledPilImage draw_embedded_image Method Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example demonstrating the internal call to draw_embedded_image. ```python img = qr.make_image(embedded_image_path='logo.png') # draw_embedded_image() is called internally during processing img.save('output.png') ``` -------------------------------- ### SvgCircleDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example of creating a QR code image using SvgCircleDrawer with SvgImage factory. ```python from qrcode.image.svg import SvgImage from qrcode.image.styles.moduledrawers.svg import SvgCircleDrawer img = qrcode.make( 'SVG Circles', image_factory=SvgImage, module_drawer=SvgCircleDrawer() ) img.save('svg_circles.svg') # Using string alias img = qrcode.make( 'SVG', image_factory=SvgImage, module_drawer='circle' ) ``` -------------------------------- ### print_ascii() method examples Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Examples of printing QR codes using ASCII characters to stdout, a string buffer, with TTY colors, and inverted. ```python import io qr = qrcode.QRCode() qr.add_data('ASCII QR') qr.make() # Print to stdout (default) qr.print_ascii() ``` ```python # Print to string buffer f = io.StringIO() qr.print_ascii(out=f) ascii_output = f.getvalue() ``` ```python # Print with TTY colors qr.print_ascii(tty=True) ``` ```python # Print inverted (suitable for dark terminals) qr.print_ascii(invert=True) ``` -------------------------------- ### Using PyPNGImage factory Source: https://github.com/lincolnloop/python-qrcode/blob/main/README.rst Example of using the PyPNGImage factory explicitly in Python. ```python import qrcode from qrcode.image.pure import PyPNGImage img = qrcode.make('Some data here', image_factory=PyPNGImage) ``` -------------------------------- ### DiamondDrawer Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md An example of a custom module drawer that draws QR code modules as diamonds. ```python from qrcode.image.styles.moduledrawers.pil import StyledPilQRModuleDrawer from PIL import ImageDraw class DiamondDrawer(StyledPilQRModuleDrawer): """Draws modules as diamonds.""" def initialize(self, *args, **kwargs): super().initialize(*args, **kwargs) self.imgDraw = ImageDraw.Draw(self.img._img) def drawrect(self, box, is_active: bool): if is_active: # Convert box to diamond coordinates x0, y0 = box[0] x1, y1 = box[1] cx, cy = (x0 + x1) / 2, (y0 + y1) / 2 points = [ (cx, y0), # top (x1, cy), # right (cx, y1), # bottom (x0, cy), # left ] self.imgDraw.polygon(points, fill=self.img.paint_color) ``` ```python # Usage from qrcode.image.styledpil import StyledPilImage import qrcode qr = qrcode.QRCode(image_factory=StyledPilImage) qr.add_data('Diamonds') qr.make() img = qr.make_image(module_drawer=DiamondDrawer()) img.save('diamonds.png') ``` -------------------------------- ### Importing SquareModuleDrawer Source: https://github.com/lincolnloop/python-qrcode/blob/main/CHANGES.rst Example showing the old and new way to import SquareModuleDrawer. ```python from qrcode.image.styles.moduledrawers import SquareModuleDrawer # Old from qrcode.image.styles.moduledrawers.pil import SquareModuleDrawer # New ``` -------------------------------- ### get_matrix() method example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example of retrieving the QR code modules as a 2D boolean array, including the border. ```python qr = qrcode.QRCode(border=1) qr.add_data('Matrix') qr.make() matrix = qr.get_matrix() # matrix is a list of lists of booleans for row in matrix: for module in row: print('#' if module else ' ', end='') print() ``` -------------------------------- ### Error correction usage example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example of using error correction levels. ```python import qrcode # Higher error correction for codes that will be printed/displayed qr = qrcode.QRCode(error_correction=qrcode.ERROR_CORRECT_H) qr.add_data('Important data') ``` -------------------------------- ### Pipe ascii output to text file in command line Source: https://github.com/lincolnloop/python-qrcode/blob/main/README.rst Command line example to pipe ASCII output to a text file. ```bash qr --ascii "Some data" > "test.txt" cat test.txt ``` -------------------------------- ### Save to File Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example of saving the generated QR code directly to a file. ```bash # Save to file qr --output=qr.png "File output" ``` -------------------------------- ### MaskPattern Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example of setting mask pattern when creating a QRCode object. ```python import qrcode # Let QRCode automatically choose best pattern qr = qrcode.QRCode(mask_pattern=None) qr.add_data('Auto') qr.make() # Internally calls best_mask_pattern() # Force specific pattern qr = qrcode.QRCode(mask_pattern=3) # Diagonal qr.add_data('Diagonal') qr.make() ``` -------------------------------- ### RoundedModuleDrawer Example (Maximum Rounding) Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/module-drawers.md Example demonstrating RoundedModuleDrawer with maximum rounding (radius_ratio=1), where isolated modules become circles. ```python from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer # Maximum rounding (isolated modules become circles) img = qr.make_image(module_drawer=RoundedModuleDrawer(radius_ratio=1)) img.save('rounded_max.png') ``` -------------------------------- ### ImageColorMask Example Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/color-masks.md Examples of how to use ImageColorMask with a file path or a PIL Image object. ```python from qrcode.image.styles.colormasks import ImageColorMask # Use image file img = qr.make_image( color_mask=ImageColorMask(color_mask_path='gradient.png') ) img.save('image_colored.png') # Use PIL Image object from PIL import Image as PILImage color_img = PILImage.open('pattern.png') img = qr.make_image( color_mask=ImageColorMask(color_mask_image=color_img) ) img.save('image_colored.png') ``` -------------------------------- ### StyledPilImage Options Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example of using StyledPilImage with various styling options like rounded modules, gradients, and embedded images. ```Python from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer from qrcode.image.styles.colormasks import RadialGradiantColorMask img = qr.make_image( image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer(), eye_drawer=None, color_mask=RadialGradiantColorMask(), embedded_image_path="/path/to/logo.png", embedded_image_ratio=0.25, embedded_image_resample=PIL.Image.Resampling.LANCZOS, ) ``` -------------------------------- ### Data Flow Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Demonstrates the typical data flow through the QR code encoding pipeline, from raw data to image generation. ```python import qrcode from qrcode.util import optimal_data_chunks, QRData # 1. Input raw data raw_data = "HELLO123World" # 2. Optionally optimize into chunks chunks = list(optimal_data_chunks(raw_data, minimum=3)) # chunks = [QRData("HELLO", mode=2), QRData("123", mode=1), # QRData("World", mode=4)] # 3. Create QRCode and add data qr = qrcode.QRCode() qr.add_data(raw_data) # Uses optimal_data_chunks internally # 4. Call make() to compile qr.make(fit=True) # Selects best version, applies mask pattern # 5. Generate image img = qr.make_image() img.save('output.png') ``` -------------------------------- ### PilImage Example Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of creating and saving a colored and transparent QR code using PilImage. ```python import qrcode qr = qrcode.QRCode(image_factory=qrcode.image.pil.PilImage) qr.add_data('PIL Image') qr.make() # Create image with colors img = qr.make_image(fill_color="blue", back_color="yellow") img.save('colored_qr.png') # Create with transparency img = qr.make_image(back_color="transparent") img.save('transparent_qr.png') # Use as default img = qrcode.make('Default PNG', box_size=10) ``` -------------------------------- ### print_tty() method example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example of printing a QR code with TTY colors to the terminal. ```python import sys qr = qrcode.QRCode() qr.add_data('TTY QR') qr.make() # Print colored QR code to terminal qr.print_tty(out=sys.stdout) ``` -------------------------------- ### ASCII Output Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example for generating QR code as ASCII art. ```bash # ASCII output qr --ascii "ASCII Art" > qr.txt ``` -------------------------------- ### ModulesType Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example showing how to access and iterate over the QR code's module grid. ```python import qrcode qr = qrcode.QRCode(border=0) r.add_data('Test') r.make() # Access module grid directly modules = qr.modules # type: ModulesType print(f"Grid size: {len(modules)}x{len(modules[0])}") # Iterate over modules for row in modules: for module in row: if module: print('#', end='') # dark else: print(' ', end='') # light print() ``` -------------------------------- ### QRData Class Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Example usage of the QRData class with different modes and validation options. ```python from qrcode.util import QRData, MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE # Auto-detect mode (most common usage) data = QRData('Hello World') assert data.mode == MODE_8BIT_BYTE # Numeric-only data numeric_data = QRData('123456') assert numeric_data.mode == MODE_NUMBER # Alphanumeric (uppercase, digits, space, $%*+-./:) alpha_data = QRData('HELLO WORLD') assert alpha_data.mode == MODE_ALPHA_NUM # Explicit mode specification explicit = QRData('12345', mode=MODE_NUMBER, check_data=True) # Skip validation (for performance with known-valid data) fast = QRData(b'Binary', mode=MODE_8BIT_BYTE, check_data=False) ``` -------------------------------- ### SVG with Circular Modules Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example demonstrating how to create an SVG image with circular modules using the `circle` drawer. ```bash # Create SVG with circular modules qr --factory=svg-path --factory-drawer=circle "Hello World" > qr.svg ``` -------------------------------- ### RGB Color Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example of using RGB and RGBA color tuples with qrcode.make(). ```python from qrcode.image.pil import PilImage # RGB color img = qrcode.make( 'RGB', image_factory=PilImage, fill_color=(0, 0, 255), # blue back_color=(255, 255, 255) # white ) # RGBA with transparency from qrcode.image.styles.colormasks import SolidFillColorMask mask = SolidFillColorMask( back_color=(255, 255, 255, 128), # white, 50% transparent front_color=(0, 0, 0, 255) # black, opaque ) # Color names (PIL only) img = qrcode.make( 'Named', image_factory=PilImage, fill_color='darkblue', back_color='yellow' ) # Special colors img = qrcode.make( 'Transparent', image_factory=PilImage, back_color='transparent' # RGBA mode with transparent background ) ``` -------------------------------- ### check_version Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Demonstrates how to use the check_version function to validate QR code version numbers. ```python from qrcode.util import check_version check_version(1) # OK check_version(20) # OK check_version(40) # OK check_version(0) # ValueError check_version(41) # ValueError ``` -------------------------------- ### ImportError: PIL/Pillow not installed Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/errors.md Example of catching an ImportError when Pillow is not installed and falling back to another image factory. ```python ImportError("PIL library not found.") ``` ```python from qrcode.image.pil import PilImage try: img = qrcode.make('Test', image_factory=PilImage) except ImportError: print("Pillow is required for PIL image support") print("Install with: pip install pillow") # Fallback to PyPNG from qrcode.image.pure import PyPNGImage img = qrcode.make('Test', image_factory=PyPNGImage) ``` -------------------------------- ### Styled Image Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/README.rst Code example to draw a QR code with rounded corners, radial gradient, and an embedded image using StyledPilImage. ```python import qrcode from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer from qrcode.image.styles.colormasks import RadialGradiantColorMask qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H) qr.add_data('Some data') img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer()) img_2 = qr.make_image(image_factory=StyledPilImage, color_mask=RadialGradiantColorMask()) img_3 = qr.make_image(image_factory=StyledPilImage, embedded_image_path="/path/to/image.png") ``` -------------------------------- ### clear() method example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Demonstrates how to clear a QRCode instance to reuse it for new data. ```python qr = qrcode.QRCode() qr.add_data('First QR Code') qr.make() # Clear to reuse the same QRCode instance qr.clear() qr.add_data('Second QR Code') qr.make() ``` -------------------------------- ### Encoding Modes Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example demonstrating how to determine the optimal encoding mode for given data. ```python from qrcode.util import optimal_mode, MODE_NUMBER, MODE_ALPHA_NUM, MODE_8BIT_BYTE # Determine optimal encoding mode assert optimal_mode(b'12345') == MODE_NUMBER assert optimal_mode(b'HELLO WORLD') == MODE_ALPHA_NUM assert optimal_mode(b'hello world') == MODE_8BIT_BYTE # lowercase not in alpha_num assert optimal_mode(b'\x00\x01\x02') == MODE_8BIT_BYTE # binary data ``` -------------------------------- ### SolidFillColorMask Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/color-masks.md Example usage of SolidFillColorMask to create QR codes with solid colors and transparent backgrounds. ```python import qrcode from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.colormasks import SolidFillColorMask qr = qrcode.QRCode(image_factory=StyledPilImage) qr.add_data('Solid Colors') qr.make() # Blue on white img = qr.make_image( color_mask=SolidFillColorMask( back_color=(255, 255, 255), front_color=(0, 0, 255) ) ) img.save('blue_white.png') # Transparent background img = qr.make_image( color_mask=SolidFillColorMask( back_color=(255, 255, 255, 0), front_color=(0, 0, 0) ) ) img.save('transparent.png') ``` -------------------------------- ### Using make_image with embeded_image arguments Source: https://github.com/lincolnloop/python-qrcode/blob/main/CHANGES.rst Example showing the old and new arguments for embeded_image and embeded_image_path in QRCode.make_image. ```python qr = QRCode() qr.make_image(embeded_image=..., embeded_image_path=...) # Old qr.make_image(embedded_image=..., embedded_image_path=...) # New StyledPilImage(embeded_image=..., embeded_image_path=...) # Old StyledPilImage(embedded_image=..., embedded_image_path=...) # New ``` -------------------------------- ### Executing qrcode as a Python module Source: https://github.com/lincolnloop/python-qrcode/blob/main/CHANGES.rst Example of how to execute the qrcode library as a Python module. ```bash python -m qrcode --output qrcode.png "hello world" ``` -------------------------------- ### Custom Configuration Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example of custom settings for a high-reliability QR code. ```python import qrcode # Custom settings for high-reliability code qr = qrcode.QRCode( version=5, # Fixed size (37×37) error_correction=qrcode.ERROR_CORRECT_H, # 30% recovery box_size=20, # 20 pixels per module border=2, # Minimal border mask_pattern=3, # Diagonal pattern ) qr.add_data('Important data') qr.make() img = qr.make_image() ``` -------------------------------- ### Parameter Validation at Construction Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/errors.md Example demonstrating how to validate input parameters before creating a QRCode object to prevent errors. ```python import qrcode # Good: Validate before use def create_qr_code(data, version=None, box_size=10, border=4): # Validate inputs if not isinstance(data, (str, bytes)): raise TypeError("Data must be string or bytes") if box_size <= 0: raise ValueError("box_size must be positive") if border < 0: raise ValueError("border must be non-negative") if version is not None and not (1 <= version <= 40): raise ValueError("version must be 1-40") # Now safe to create qr = qrcode.QRCode( version=version, box_size=box_size, border=border ) qr.add_data(data) return qr # Safe usage qr = create_qr_code('Hello', version=5, box_size=10) ``` -------------------------------- ### QRData Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/types.md Example demonstrating the usage of the QRData class for different encoding modes and accessing its length. ```python from qrcode.util import QRData, MODE_NUMBER, MODE_8BIT_BYTE # Automatically determine mode (numeric) data1 = QRData('12345') assert data1.mode == MODE_NUMBER # Explicitly specify mode data2 = QRData('ABC', mode=MODE_ALPHA_NUM) # 8-bit byte mode for any data data3 = QRData(b'Hello!') assert data3.mode == MODE_8BIT_BYTE # Access length print(len(data1)) # 5 ``` -------------------------------- ### Basic Module Drawers Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Examples of basic module drawers like SquareModuleDrawer, CircleModuleDrawer, GappedSquareModuleDrawer, and GappedCircleModuleDrawer. Some accept a size_ratio parameter. ```python from qrcode.image.styles.moduledrawers.pil import ( SquareModuleDrawer, CircleModuleDrawer, GappedSquareModuleDrawer, GappedCircleModuleDrawer, ) # No parameters drawer = SquareModuleDrawer() # With size_ratio (0-1) drawer = GappedSquareModuleDrawer(size_ratio=0.7) drawer = GappedCircleModuleDrawer(size_ratio=0.8) ``` -------------------------------- ### SVG image creation Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example of creating an SVG image using the SvgPathImage factory. ```python from qrcode.image.svg import SvgPathImage img = qr.make_image(image_factory=SvgPathImage) ``` -------------------------------- ### Image creation with defaults and custom colors Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Examples of creating QR code images with default settings and custom fill/background colors using PIL. ```python img = qr.make_image() ``` ```python img = qr.make_image(fill_color="darkblue", back_color="white") ``` -------------------------------- ### Disable Optimization Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example of disabling data chunk optimization. ```bash # Disable optimization qr --optimize=0 "12345ABCDE" > optimized.png ``` -------------------------------- ### lost_point Example Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrdata-utilities.md Demonstrates calculating the quality score (lost point) for a QR code pattern. ```python import qrcode from qrcode.util import lost_point qr = qrcode.QRCode() qr.add_data('Quality') qr.make() score = lost_point(qr.modules) print(f"Lost point score: {score}") # Lower score = better visual appearance for reading ``` -------------------------------- ### print_ascii() Options Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example showcasing the use of print_ascii() with different output streams, TTY color codes, and inversion for terminal display. ```Python qr.print_ascii(out=None, tty=False, invert=False) ``` ```Python import io qr = qrcode.QRCode() qr.add_data('ASCII') qr.make() # Print to stdout qr.print_ascii() # Print to string output = io.StringIO() qr.print_ascii(out=output) text = output.getvalue() # Terminal with colors qr.print_ascii(tty=True) # Inverted (for dark terminal backgrounds) qr.print_ascii(invert=True) ``` -------------------------------- ### add_data() Options Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example showing how to use the optimize parameter in add_data() to control mode optimization, including disabling it and manually controlling data encoding with QRData. ```Python qr.add_data(data, optimize=20) ``` ```Python qr = qrcode.QRCode() # Optimization enabled (default) # "HELLO" + "123" → different chunks, different encoding modes qr.add_data('HELLO123WORLD', optimize=20) # Disable optimization # Entire string in single MODE_8BIT_BYTE chunk qr.add_data('HELLO123WORLD', optimize=0) # Manual control with QRData from qrcode.util import QRData, MODE_ALPHA_NUM qr.add_data(QRData('HELLO', mode=MODE_ALPHA_NUM, check_data=True)) ``` -------------------------------- ### Styled image with module drawer Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/qrcode-main.md Example of creating a styled QR code image using StyledPilImage and RoundedModuleDrawer. ```python from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer img = qr.make_image( image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer() ) ``` -------------------------------- ### PyPNGImage save method Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of saving a PyPNGImage to a file or stream. ```python from qrcode.image.pure import PyPNGImage qr = qrcode.QRCode(image_factory=PyPNGImage) qr.add_data('Pure Python PNG') img = qr.make_image() # Save to file img.save('output.png') # Save to stream import io buffer = io.BytesIO() img.save(buffer) ``` -------------------------------- ### SvgFragmentImage constructor and save method Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/image-factories.md Example of creating and saving an SVG fragment image. ```python from qrcode.image.svg import SvgFragmentImage img = qrcode.make( 'SVG Fragment', image_factory=SvgFragmentImage ) img.save('fragment.svg') # With custom drawer from qrcode.image.styles.moduledrawers.svg import SvgCircleDrawer img = qrcode.make( 'SVG Fragment', image_factory=SvgFragmentImage, module_drawer=SvgCircleDrawer() ) img.save('circles.svg') ``` -------------------------------- ### Or if you want to show qr on fly Source: https://github.com/lincolnloop/python-qrcode/wiki/Home Generates a QR code and displays it. ```python import qrcode qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4, ) qr.add_data('Some data') qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") img.show() ``` -------------------------------- ### ValueError for Invalid version Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/errors.md Examples of ValueError raised for invalid version settings. ```python try: qr = qrcode.QRCode(version=100) except ValueError as e: print(f"Invalid version: {e}") try: qr = qrcode.QRCode() qr.version = 0 except ValueError: print("Version must be 1-40") ``` -------------------------------- ### High Error Correction Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Example showing how to set a high error correction level for a QR code. ```bash # High error correction qr --error-correction=H "Important" > important.png ``` -------------------------------- ### QRColorMask.initialize Method Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/color-masks.md Initialize the color mask with the styled image. Called once before apply_mask(). Use for setup that depends on image size, etc. ```python def initialize(self, styledPilImage, image): pass ``` -------------------------------- ### Advanced Module Drawers Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Examples of advanced module drawers including RoundedModuleDrawer, VerticalBarsDrawer, and HorizontalBarsDrawer. These accept parameters like radius_ratio and shrink values. ```python from qrcode.image.styles.moduledrawers.pil import ( RoundedModuleDrawer, VerticalBarsDrawer, HorizontalBarsDrawer, ) # Rounded corners drawer = RoundedModuleDrawer(radius_ratio=0.5) # 0-1 # Vertical bars drawer = VerticalBarsDrawer(horizontal_shrink=0.7) # 0-1 # Horizontal bars drawer = HorizontalBarsDrawer(vertical_shrink=0.7) # 0-1 ``` -------------------------------- ### Release Command Source: https://github.com/lincolnloop/python-qrcode/blob/main/PACKAGING.rst Command to run the release process using zest.releaser. ```bash uv run fullrelease ``` -------------------------------- ### Run a quick test Source: https://github.com/lincolnloop/python-qrcode/blob/main/TESTING.rst Performs a fast test in the current environment. ```bash just test quick ``` -------------------------------- ### VerticalGradiantColorMask Example Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/color-masks.md Example of how to use VerticalGradiantColorMask to create a QR code with a vertical gradient. ```python from qrcode.image.styles.colormasks import VerticalGradiantColorMask # Black top to green bottom img = qr.make_image( color_mask=VerticalGradiantColorMask( top_color=(0, 0, 0), bottom_color=(0, 255, 0) ) ) img.save('vertical_gradient.png') ``` -------------------------------- ### PilImage Options Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/configuration.md Options passed to `make_image()` when using PilImage factory. ```python img = qr.make_image( image_factory=qrcode.image.pil.PilImage, fill_color="black", back_color="white", ) ``` -------------------------------- ### HorizontalGradiantColorMask Example Usage Source: https://github.com/lincolnloop/python-qrcode/blob/main/_autodocs/api-reference/color-masks.md Example of how to use HorizontalGradiantColorMask to create a QR code with a horizontal gradient. ```python from qrcode.image.styles.colormasks import HorizontalGradiantColorMask # Black left to red right img = qr.make_image( color_mask=HorizontalGradiantColorMask( left_color=(0, 0, 0), right_color=(255, 0, 0) ) ) img.save('horizontal_gradient.png') ```