### QR Code Image Examples
Source: https://github.com/heuer/segno/blob/master/docs/comparison-qrcode-libs.rst
Examples of QR codes generated by Segno and other libraries, illustrating different versions, error correction levels, and mask patterns. These images are used for visual comparison in performance benchmarks.
```text
.. |ISO 1-M| image:: _static/iso_fig1_1m.png
:alt: 1-M QR code encoding 'QR Code Symbol'
:width: 75
:height: 75
.. |ISO M2-L| image:: _static/iso_fig2_m2l.png
:alt: M2-L Micro QR code encoding '01234567'
:width: 51
:height: 51
.. |mask4 1-M| image:: _static/iso_fig1_1m_mask4.png
:alt: 1-M QR code encoding 'QR Code Symbol' using mask 4
:width: 75
:height: 75
.. |segno 1-M| image:: _static/iso_fig1_1m_segno.png
:alt: 1-M QR code encoding 'QR Code Symbol' using mask 5
:width: 75
:height: 75
.. |segno M2-L| image:: _static/iso_fig2_m2l_segno.png
:alt: M2-L Micro QR code encoding '01234567'
:width: 51
:height: 51
```
--------------------------------
### Segno CLI Basic Usage Examples
Source: https://github.com/heuer/segno/blob/master/docs/man/segno.rst
Demonstrates fundamental ways to use the Segno command-line tool, including generating QR codes to the terminal and saving them to files with basic options.
```bash
$ segno "Up jumped the devil"
Prints a 2-Q QR code to the terminal
```
```bash
$ segno --compact "I am the walrus"
Prints a 1-L QR code to the terminal in a more compact manner
```
```bash
$ segno -o=yesterday.png "Yesterday"
Saves the 1-Q QR code as PNG image.
```
--------------------------------
### Segno Plugin Setup Configuration
Source: https://github.com/heuer/segno/blob/master/docs/plugins.rst
This setup.py script configures a Segno plugin named 'simple-plugin'. It specifies the package details and registers the 'simple' plugin under the 'segno.plugin.converter' entry point, linking it to the 'simple_plugin:write' function.
```setup.py
from setuptools import setup
setup(
name='simple-plugin',
version='1.0',
license='BSD',
author='John Doe',
author_email='john@example.org',
platforms=['any'],
py_modules=['simple_plugin'],
entry_points="""
[segno.plugin.converter]
simple = simple_plugin:write
""",
install_requires=['segno'],
)
```
--------------------------------
### Segno Packaging and Setup
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Details changes related to Segno's packaging and build process. This includes switching from setuptools to flit, ensuring man pages and test suites are included in source distributions, and adopting PEP 517 for packaging.
```python
# Switched from setuptools to flit for setup
# Added support for PEP 517
# Fixed packaging: include man page, source distribution did not contain all relevant files such as docs and test suite.
```
--------------------------------
### Segno QR Code Generation Example
Source: https://github.com/heuer/segno/blob/master/tests/ref_matrix/seq-iso-04-04.txt
Demonstrates how to generate a QR code using the Segno library in Python. This snippet shows basic usage for creating a QR code with default settings.
```Python
import segno
qrcode = segno.make_qr('Hello, Segno!')
qrcode.save('hello_segno.png')
print('QR code saved to hello_segno.png')
```
--------------------------------
### Segno CLI Advanced Usage Examples
Source: https://github.com/heuer/segno/blob/master/docs/man/segno.rst
Illustrates more advanced usage scenarios for Segno, including saving QR codes as SVG with custom titles, applying scaling factors and custom colors to SVG modules, and generating Micro QR codes with specific PNG output settings.
```bash
$ segno -o=fool.svg --title="Example QR code" "The Fool on the Hill"
Saves the 2-Q QR code as SVG document with the given title.
```
```bash
$ segno -o=a-day-in-the-life.svg --scale=10 --dark darkblue "A Day in the Life"
Saves the 1-L QR code as SVG document, using a scaling factor of 10 and the
dark modules use the color "darkblue" instead of black.
```
```bash
$ segno -o rain.png -s 4 --dark "#003399" --micro RAIN
Saves the Micro QR Code (M2-M) as PNG image, using the color #003399 for dark
modules. Each module corresponds to 4 x 4 pixels because the scaling factor
was set to 4.
```
--------------------------------
### Basic QR Code Generation
Source: https://github.com/heuer/segno/blob/master/tests/ref_matrix/fig-23-unmasked.txt
Generates a basic QR code with default settings. This is a simple starting point for creating QR codes.
```python
import segno
qrcode = segno.make_qr('Hello, Segno!')
qrcode.save('hello.png')
```
--------------------------------
### Using the Simple Segno Plugin
Source: https://github.com/heuer/segno/blob/master/docs/plugins.rst
This Python code demonstrates how to use the installed 'simple' Segno plugin. It creates a QR code for the text 'Chelsea Hotel No. 2' and then calls the custom 'to_simple()' method to render it using the plugin's logic.
```python
>>> import segno
>>> qrcode = segno.make('Chelsea Hotel No. 2')
>>> qrcode.to_simple()
XXXXXXX_XXXX_XX_X_XXXXXXX
X_____X___________X_____X
X_XXX_X_XX__XXX___X_XXX_X
X_XXX_X__X_XXX_X__X_XXX_X
X_XXX_X__XX_XX__X_X_XXX_X
X_____X_X__XXX__X_X_____X
XXXXXXX_X_X_X_X_X_XXXXXXX
__________X_X__XX________
X_X___XX__XXXXX_X__X__X_X
_XX__X_XXXXXX__XX_XX_X__X
_X____X____X_XXXX__XX_X_X
_XX__X_XX_XXX__XXXX_XX___
__X_XXXX_XXX_XX_X_XXXX_X_
_____X_X_X___X__XXXX_XX_X
XXXXX_X_X_XX___XX_XXXXX_X
____XX__XXX__X_______X_XX
XX_X__X__XXXXX_XXXXXX__XX
________X_X_X___X___X____
XXXXXXX_X___XXX_X_X_X___X
X_____X__X_XX_X_X___XX_XX
X_XXX_X___X__XXXXXXXXX_XX
X_XXX_X______XX__X__XX_X_
X_XXX_X_XXXX_____X_XX_XXX
X_____X___X__X__XX_X_X___
XXXXXXX_XXXXXX__X_XXXX__X
```
--------------------------------
### Colorful QR Codes Example
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Demonstrates how to create QR codes with multiple colors for different module types using the `colormap` parameter, and the newer, preferred method using individual color parameters like `dark`, `data_dark`, and `data_light`. This showcases the library's flexibility in generating visually distinct QR codes.
```python
import segno
import segno.moduletypes as mt
qr = segno.make_qr('example data')
# Deprecated usage:
colormap = {
mt.TYPE_FINDER_PATTERN_DARK: 'darkred',
mt.TYPE_ALIGNMENT_PATTERN_DARK: 'darkred',
mt.TYPE_TIMING_DARK: 'darkred',
mt.TYPE_DARKMODULE: 'darkred',
mt.TYPE_DATA_DARK: 'darkorange',
mt.TYPE_DATA_LIGHT: 'yellow',
mt.TYPE_FORMAT_DARK: 'darkred'
}
qr.save('qrcode_deprecated.png', scale=5, colormap=colormap)
# Recommended usage:
qr.save('qrcode_recommended.png', scale=5, dark='darkred', data_dark='darkorange',
data_light='yellow')
# For more details on module names, see: https://segno.readthedocs.io/en/stable/colorful-qrcodes.html
```
--------------------------------
### Add Text to QR Code (Python)
Source: https://github.com/heuer/segno/blob/master/examples/qrcode_text/README.rst
This example shows how to add text to a QR code using the Segno library in Python. It requires the Pillow library for image manipulation.
```python
import segno
from PIL import Image, ImageDraw, ImageFont
# Create a QR code
qrcode = segno.make_qr('This is a QR code with text')
# Save it as a PNG file
qrcode.save('qr_with_text.png')
# --- Adding text to the QR code image ---
# Open the QR code image
img = Image.open('qr_with_text.png').convert('RGB')
draw = ImageDraw.Draw(img)
# Define text and font
text = "Additional Text"
# Try to load a default font, fallback if not found
try:
font = ImageFont.truetype("arial.ttf", 15)
except IOError:
font = ImageFont.load_default()
# Get text size to center it
text_width, text_height = draw.textsize(text, font=font)
# Calculate position for the text (e.g., below the QR code)
img_width, img_height = img.size
x = (img_width - text_width) / 2
y = img_height - text_height - 10 # 10 pixels padding from bottom
# Draw the text
draw.text((x, y), text, fill=(0, 0, 0), font=font)
# Save the modified image
img.save('qr_with_additional_text.png')
print("QR code with additional text saved as 'qr_with_additional_text.png'")
```
--------------------------------
### Example SVG XML Output
Source: https://github.com/heuer/segno/blob/master/docs/svg-options.rst
Shows the typical XML structure of a Segno-generated SVG file, including the XML declaration and UTF-8 encoding.
```xml
```
--------------------------------
### Get MeCard Data String
Source: https://github.com/heuer/segno/blob/master/docs/contact-information.rst
Generates the MeCard formatted string directly, which can then be used to create a QR code using Segno's `make` function. This is useful if you need the raw data before encoding.
```python
import segno
from segno import helpers
mecard = helpers.make_mecard_data(name='Doe,John', email='me@example.org', phone='+1234567')
mecard
qrcode = segno.make(mecard, error='H')
```
--------------------------------
### Get vCard Data String
Source: https://github.com/heuer/segno/blob/master/docs/contact-information.rst
Generates the vCard formatted string directly, which can then be used to create a QR code using Segno's `make` function. This provides the raw vCard data before QR code encoding.
```python
import segno
from segno import helpers
vcard = helpers.make_vcard_data(name='Doe;John', displayname='John Doe',
email='me@example.org', phone='+1234567')
vcard
qrcode = segno.make(vcard, error='H')
```
--------------------------------
### API Documentation Improvements
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
General improvements to API documentation across multiple versions, including added examples and fixes.
```APIDOC
* Improved API docs
```
```APIDOC
* Improved documentation
```
```APIDOC
* Documentation improvements
```
```APIDOC
* Documentation improvements (also thanks to `James Addison `_
for pr `#73 `_)
```
```APIDOC
* Documentation improvements
```
```APIDOC
* Documentation improvements
```
```APIDOC
* Documentation improvements: Added several examples, fixed docs
```
--------------------------------
### Project Requirements
Source: https://github.com/heuer/segno/blob/master/tests/requirements.txt
These are the Python packages required to install and run the Segno project, including dependencies for testing and image generation.
```python
pytest
pytest-cov
pypng~=0.0.20
pyzbar~=0.1.8
qrcode-artistic
Pillow
importlib-metadata>=3.6.0; python_version < '3.10'
```
--------------------------------
### Segno CLI Options for Colors
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Illustrates the command-line interface options for setting QR code colors. It highlights the transition from older keywords (`--color`, `--background`) to newer, more specific ones (`--dark`, `--light`), while maintaining backward compatibility. The former keywords will issue deprecation warnings.
```bash
# Using new keywords (recommended):
segno --dark=darkred --light=yellow input.txt output.png
# Using deprecated keywords (will issue warnings in the future):
segno --color=darkred --background=yellow input.txt output.png
```
--------------------------------
### Segno Features Overview
Source: https://github.com/heuer/segno/blob/master/docs/comparison-qrcode-libs.rst
This table summarizes the features supported by Segno, including animated QR codes, module scaling, command-line script availability, and plugin support. It also details default encoding and third-party dependencies.
```text
Feature Animated QR Codes Command Line Script Plugins
Animated QR Codes (`GIF`_, `APNG`_, `WebP`_) No No Yes via `plugin`_
Changing size of modules (scaling factor) Yes No Yes
Command line script Yes No Yes
Plugins No No Yes
Default encoding in Byte mode ISO/IEC 8859-1 ISO/IEC 8859-1 ISO/IEC 8859-1
or UTF-8 or UTF-8 or UTF-8
3rd party dependencies `Pillow`_ or - -
`Pymaging`_ and
`Pymaging-PNG`_
(Windows:
`colorama`_)
```
--------------------------------
### Disallow Micro QR Codes
Source: https://github.com/heuer/segno/blob/master/docs/make.rst
Example of creating a QR code while explicitly disallowing Micro QR Codes using the `micro=False` parameter in `segno.make`.
```python
import segno
qrcode = segno.make('The Beatles', micro=False) # Disallow Micro QR Codes
print(qrcode.designator)
# Expected output: 1-Q
```
--------------------------------
### QR Code Serialization to Multiple Formats
Source: https://github.com/heuer/segno/blob/master/docs/command-line.rst
Demonstrates serialization to various supported formats including EPS, PDF, SVGZ (compressed SVG), and TXT.
```bash
$ segno --output=mrs.eps "Mrs. Robinson"
$ segno --output=dedodo.pdf "De Do Do Do, De Da Da Da"
$ segno --output=tin-pan-alley.svgz "Tin Pan Alley"
$ segno --output=thrill-gone.txt "The Thrill Is Gone"
```
--------------------------------
### Byte Mode Encoding
Source: https://github.com/heuer/segno/blob/master/docs/qrcode-modes.rst
Demonstrates encoding arbitrary data using the Byte mode, which is used when other modes are not applicable. Shows examples for both standard QR Codes and Micro QR Codes.
```python
import segno
# Encoding with Byte mode (standard QR Code)
qrcode = segno.make('Turn off your mind relax and float down stream')
print(f"Designator: {qrcode.designator}, Mode: {qrcode.mode}")
# Encoding with Byte mode (Micro QR Code)
qrcode_micro = segno.make('Let it be')
print(f"Designator: {qrcode_micro.designator}, Mode: {qrcode_micro.mode}")
```
--------------------------------
### Segno Version Information
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
The Segno command-line script now includes a '-V' shortcut to display the library's version information. The version is also included in the help message.
```bash
# Display Segno version
segno --version
segno -V
```
--------------------------------
### Django QR Code Form Example
Source: https://github.com/heuer/segno/blob/master/examples/django_qrcode/qrcode/templates/qrcode/example.html
Demonstrates a basic Django form for QR code creation, including CSRF token protection and form rendering. It implies validation rules for the QR code name.
```HTML
{% csrf_token %} {{ form }}
```
--------------------------------
### Command Line QR Code Generation (Bash)
Source: https://github.com/heuer/segno/blob/master/README.rst
Demonstrates generating QR codes directly from the command line. It shows basic text encoding, saving to a file with specified output format, and customizing appearance with scale, color, and border options.
```bash
$ segno "Comfortably Numb"
$ segno -o=raincoat.svg "Famous Blue Raincoat"
$ segno --scale 10 --dark darkblue --border 0 --output=fire.svg "Who by Fire"
$ segno --scale 10 --light transparent --output=miracle.png "Waiting for the Miracle"
```
--------------------------------
### Create Colorful Micro QR Code with Custom Colors
Source: https://github.com/heuer/segno/blob/master/docs/colorful-qrcodes.rst
Generates a Micro QR code with custom colors for dark and light modules. This example shows setting 'dark' and 'data_dark' for a Micro QR code.
```python
import segno
micro_qrcode = segno.make('Rain', error='q')
micro_qrcode.save('micro_qrode_rain.png', scale=4, dark='darkblue', data_dark='steelblue')
```
--------------------------------
### Code Quality and Tooling Updates
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Updates related to code quality and development tooling, including switching from `tox` to `nox` and utilizing `flake8` for linting. Metadata management was also moved from `setup.py` to `setup.cfg`.
```python
* Switched from `tox `_ to
`nox `_
```
```python
* Utilize `flake8 `_
```
```python
* Moved metadata from setup.py to setup.cfg
```
--------------------------------
### Optimized SVG QR Code Output
Source: https://github.com/heuer/segno/blob/master/docs/svg-options.rst
This example shows further optimization of the SVG output by omitting the trailing newline character using `nl=False`. This results in a smaller file size while maintaining the QR code's integrity and scalability.
```python
>>> import segno
>>> qrcode = segno.make('Penny Lane', error='h')
>>> qrcode.save('penny-lane.svg', xmldecl=False, svgns=False, svgclass=None, lineclass=None, omitsize=True, nl=False)
```
--------------------------------
### Create Colorful QR Code with Custom Colors
Source: https://github.com/heuer/segno/blob/master/docs/colorful-qrcodes.rst
Generates a QR code with custom colors for dark and light modules, as well as data modules. This example demonstrates setting 'dark', 'data_dark', and 'data_light' for a standard QR code.
```python
import segno
qrcode = segno.make('Yellow Submarine', version=7, error='h')
qrcode.save('qrcode_yellow-submarine.png', scale=4, dark='darkred',
data_dark='darkorange', data_light='yellow')
```
--------------------------------
### Segno CLI Version and Help Flags
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
The command line script now correctly reports Segno's version using the `--ver` flag and also includes version information in the help message accessible via `-h`.
```bash
# Display help message including version info
segno -h
# Display version information
segno --ver
```
--------------------------------
### Netpbm PPM Image Support
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Adds support for generating QR codes in Netpbm PPM image format, enhancing the library's output capabilities.
```python
* Added support for `Netpbm PPM `_ images.
```
--------------------------------
### QR Code Generation with Options (Python)
Source: https://github.com/heuer/segno/blob/master/README.rst
Demonstrates generating QR codes with various options such as scaling, transparency, and different output formats like PNG, PDF, and SVG. It also shows how to specify colors for the dark modules.
```python
>>> import segno
>>> # Let Segno choose the minimal version and an optimal (maximal) error
>>> # level without changing the minimal version
>>> qrcode = segno.make('Up Jumped the Devil')
>>> qrcode.designator # Returns the QR code version and the error correction level
'2-Q'
>>> qrcode.save('up-jumped-the-devil.png') # Save as PNG
>>> qrcode.save('up-jumped-the-devil-2.png', scale=10) # Scaling factor 10
>>> qrcode.save('up-jumped-the-devil-3.png', light=None) # Transparent light modules
>>> qrcode.save('up-jumped-the-devil.pdf', scale=10) # Save as PDF
>>> # SVG drawing the dark modules in "dark blue"
>>> qrcode.save('up-jumped-the-devil.svg', scale=10, dark='darkblue')
```
--------------------------------
### External Links and References
Source: https://github.com/heuer/segno/blob/master/docs/comparison-qrcode-libs.rst
A list of external links and references used throughout the documentation, including links to related projects, standards, and image formats.
```text
.. _qrcode: https://pypi.org/project/qrcode/
.. _qrcodegen: https://pypi.org/project/qrcodegen/
.. _Segno: https://pypi.org/project/segno/
.. _BSD: http://opensource.org/licenses/BSD-3-Clause
.. _MIT: http://opensource.org/licenses/MIT
.. _PNG: https://en.wikipedia.org/wiki/Portable_Network_Graphics
.. _SVG: https://en.wikipedia.org/wiki/Scalable_Vector_Graphics
.. _EPS: https://en.wikipedia.org/wiki/Encapsulated_PostScript
.. _PDF: https://en.wikipedia.org/wiki/Portable_Document_Format
.. _XBM: https://en.wikipedia.org/wiki/X_BitMap
.. _XPM: https://de.wikipedia.org/wiki/X_PixMap
.. _PAM: http://netpbm.sourceforge.net/doc/pam.html
```
--------------------------------
### Add a Logo to a QR Code using Pillow
Source: https://github.com/heuer/segno/blob/master/docs/pillow-qrcodes.rst
Provides an example of how to overlay a logo onto a QR code generated by Segno. It involves saving the QR code as a PNG, opening it with Pillow, resizing the logo, and pasting it onto the QR code image.
```python
import io
from PIL import Image
import segno
# Save the QR code into a memory buffer as PNG
out = io.BytesIO()
segno.make('Blackbird singing in the dead of night', error='h').save(out, scale=5, kind='png')
out.seek(0)
# Open the QR code image with Pillow
img = Image.open(out)
img = img.convert('RGB') # Ensure colors for the output
img_width, img_height = img.size
# Define logo size and load the logo
logo_max_size = img_height // 3 # May use a fixed value as well
logo_img = Image.open('./blackbird.jpg') # The logo
# Resize the logo
logo_img.thumbnail((logo_max_size, logo_max_size), Image.Resampling.LANCZOS)
# Calculate the center position for the logo
box = ((img_width - logo_img.size[0]) // 2, (img_height - logo_img.size[1]) // 2)
# Paste the logo onto the QR code
img.paste(logo_img, box)
# Save the final image with the logo
img.save('qrcode_with_logo.png')
```
--------------------------------
### Simple Segno Plugin Implementation
Source: https://github.com/heuer/segno/blob/master/docs/plugins.rst
This Python code defines a simple plugin for Segno that iterates through the QR code matrix and writes 'X' for dark modules and '_' for light modules to standard output, followed by a newline for each row.
```python
import sys
def write(qrcode):
write = sys.stdout.write
for row in qrcode.matrix:
for col in row:
write('X' if col else '_')
write('\n')
```
--------------------------------
### CLI Shortcut for Scaling Factor
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Adds the '-s' shortcut to Segno's command line interface, allowing users to specify the scaling factor for the generated QR code.
```bash
# Generate QR code with a scaling factor of 3
segno --scale 3 "Scaled QR"
segno -s 3 "Scaled QR"
```
--------------------------------
### Save QR Code to SVG with Custom Dark Module Color
Source: https://github.com/heuer/segno/blob/master/docs/serializers.rst
Generates a QR code for 'Sgt. Pepper’s Lonely Hearts Club Band' and saves it as an SVG file. This example shows how to specify a custom color for the dark modules in SVG format.
```python
import segno
qrcode = segno.make("Sgt. Pepper’s Lonely Hearts Club Band")
qrcode.save('sgt-peppers.svg', dark='#00fc') # Same as above but SVG
```
--------------------------------
### Segno CLI Shortcuts
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Introduces shortcuts for the Segno command-line interface. The '-s' shortcut is used for the scaling factor, and '-b' is used for the border (quiet zone).
```bash
# Generate QR code with scale factor 2 and border 4
segno --scale 2 --border 4 "My Text"
segno -s 2 -b 4 "My Text"
```
--------------------------------
### Segno CLI Documentation
Source: https://github.com/heuer/segno/blob/master/docs/man/index.rst
Provides access to the man pages for the Segno command line interface. This section outlines the structure of the documentation, with the primary entry point being the 'segno' man page.
```APIDOC
segno
Documentation of the command line interface.
.. toctree::
:maxdepth: 3
segno
```
--------------------------------
### Save QR Code to PNG with Custom Dark Module Color
Source: https://github.com/heuer/segno/blob/master/docs/serializers.rst
Generates a QR code for 'Sgt. Pepper’s Lonely Hearts Club Band' and saves it as a PNG file. This example demonstrates setting a custom color for the dark modules with alpha transparency.
```python
import segno
qrcode = segno.make("Sgt. Pepper’s Lonely Hearts Club Band")
# Dark modules with alpha transparency
qrcode.save('sgt-peppers.png', dark='#0000ffcc')
```
--------------------------------
### Save QR Code to Compressed SVG (SVGZ) with RGB Color
Source: https://github.com/heuer/segno/blob/master/docs/serializers.rst
Generates a QR code for 'Sgt. Pepper’s Lonely Hearts Club Band' and saves it as a compressed SVG (SVGZ) file. This example uses an RGB tuple to define the color of the dark modules.
```python
import segno
qrcode = segno.make("Sgt. Pepper’s Lonely Hearts Club Band")
# Anonther color, save as compressed SVG
qrcode.save('sgt-peppers.svgz', dark=(8, 90, 117))
```
--------------------------------
### PAM Serialization Format
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Introduces support for the PAM (Portable Arbitrary Map) serialization format. PAM supports both colors and transparency, offering more flexibility for image-based QR codes.
```python
import segno
qrcode = segno.make_qr('PAM Format')
qrcode.save('output.pam', scale=4)
```
--------------------------------
### Performance Benchmarks
Source: https://github.com/heuer/segno/blob/master/docs/comparison-qrcode-libs.rst
Performance indicators for Segno, based on benchmarks run on Intel i7-8559U / CPython 3.11. The benchmarks compare the creation of QR codes with different error correction levels and sizes, including SVG and PNG output.
```text
Performance
-----------
Some performance indicators. The script `benchmarks.py`_ ran on
Intel i7-8559U / CPython 3.11. Each SVG / PNG image uses a
scaling factor of 10 (aside from qrcodegen which does not support any scaling).
Create a 1-M QR code
~~~~~~~~~~~~~~~~~~~~
1-M QR code encoding "QR Code Symbol"
.. image:: _static/chart_create_1m.svg
:alt: Chart showing the results of creating a 1-M QR code.
Create a 7-Q QR code
~~~~~~~~~~~~~~~~~~~~
7-Q QR code encoding "QR Code Symbol"
.. image:: _static/chart_create_7q.svg
:alt: Chart showing the results of creating a 7-Q QR code.
Create a 30-H QR code
~~~~~~~~~~~~~~~~~~~~~
30-H QR code encoding "QR Code Symbol"
.. image:: _static/chart_create_30h.svg
:alt: Chart showing the results of creating a 30-H QR code.
Create a QR code and serialize it as SVG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a QR code 1-M "QR Code Symbol" and serialize it as SVG document.
.. image:: _static/chart_svg.svg
:alt: Chart showing the results of creating a 1-M QR code and export it as SVG image.
Create a QR code and serialize it as PNG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a QR code 1-M "QR Code Symbol" and serialize it as PNG image.
.. image:: _static/chart_png.svg
:alt: Chart showing the results of creating a 1-M QR code and export it as SVG image.
```
--------------------------------
### Segno Command Line Options
Source: https://github.com/heuer/segno/blob/master/docs/man/segno.rst
Provides a comprehensive overview of the command-line options available for the segno tool. This includes general options for version and help, QR Code specific options for version, error correction, mode, mask pattern, encoding, micro QR code support, error boost, and structured append mode. It also covers output options like scaling, file output, and terminal printing, as well as detailed module color customization for various parts of the QR code.
```APIDOC
.. program:: segno
.. option:: --ver, -V
Shows Segno's version and exit
.. option:: -h, --help
Show a help message which lists all commands and exit
QR Code Options
~~~~~~~~~~~~~~~
.. option:: --version VERSION, -v VERSION
QR Code version: 1 .. 40 or Micro Code Version "M1", "M2", "M3", "M4"
.. option:: --error {L,M,Q,H,-}, -e {L,M,Q,H,-}
Error correction level: "L": 7% (default), "M": 15%, "Q": 25%, "H": 30%,
"-": no error correction (used for M1 symbols)
.. option:: --mode {numeric,alphanumeric,byte,kanji,hanzi}, -m {numeric,alphanumeric,byte,kanji,hanzi}
Mode. If unspecified (default), an optimal mode is chosen for the given
input.
.. option:: --pattern PATTERN, -p PATTERN
Mask pattern to use. If unspecified (default), an optimal mask pattern is used.
Valid values for QR Codes: 0 .. 7
Valid values for Micro QR Codes: 0 .. 3
.. option:: --encoding ENCODING
Specifies the encoding of the provided content.
If not specified (default) either ISO 8859-1 is used or if it does
not fit, UTF-8 or Shift_JIS (for Kanji content) is used.
.. option:: --micro
Allow the creation of Micro QR Codes
.. option:: --no-micro
Disallow creation of Micro QR Codes (default)
.. option:: --no-error-boost
Disables the automatic error correction level incrementation.
By default, the maximal error correction level is used (without changing the
version).
.. option:: --seq
Creates a sequence of QR Codes (Structured Append mode).
The :option:`--version` or :option:`--symbol-count` must be provided
.. option:: --symbol-count SYMBOL_COUNT, -sc SYMBOL_COUNT
Number of symbols to create
.. option:: --border BORDER, -b BORDER
Size of the border / quiet zone of the output.
By default, the standard border (4 modules for QR Codes, 2 modules for
Micro QR Codes) will be used. A value of 0 omits the border
Output Options
~~~~~~~~~~~~~~
.. option:: --scale SCALE, -s SCALE
Scaling factor of the output.
By default, a scaling factor of 1 is used which can result into too small
images. Some output formats, i.e. SVG, accept a decimal value.
.. option:: --output OUTPUT, -o OUTPUT
Output file.
If not specified, the QR Code is printed to the terminal
.. option:: --compact
Indicates that the QR code should be printed to the terminal in a more
compact manner.
Module Colors
~~~~~~~~~~~~~
Arguments to specify the module colors. Multiple colors are supported for
SVG and PNG. The module color support varies between the serialization
formats. Most serializers support at least "--dark" and "--light".
Unsupported arguments are ignored.
.. option:: --dark DARK
Sets the (default) color of the dark modules.
The color may be specified as web color name, i.e. "red" or as hexadecimal
value, i.e. "#0033cc". Some serializers, i.e. SVG and PNG, support alpha
channels (8-digit hexadecimal value) and some support "transparent" as color
value. The standard color is black
.. option:: --light LIGHT
Sets the (default) color of the light modules.
The standard value is either white or transparent.
See :option:`--dark` for a description of allowed values.
.. option:: --align-dark ALIGN_DARK
Sets the color of the dark modules of the alignment patterns.
See :option:`--dark` for a description of allowed values.
.. option:: --align-light ALIGN_LIGHT
Sets the color of the light modules of the alignment patterns.
See :option:`--dark` for a description of allowed values.
.. option:: --dark-module DARK_MODULE
Sets the color of the dark module.
See :option:`--dark` for a description of allowed values.
.. option:: --data-dark DATA_DARK
Sets the color of the dark data modules.
See :option:`--dark` for a description of allowed values.
.. option:: --data-light DATA_LIGHT
Sets the color of the light data modules.
See :option:`--dark` for a description of allowed values.
.. option:: --finder-dark FINDER_DARK
Sets the color of the dark modules of the finder pattern.
See :option:`--dark` for a description of allowed values.
.. option:: --finder-light FINDER_LIGHT
Sets the color of the light modules of the finder pattern.
See :option:`--dark` for a description of allowed values.
.. option:: --format-dark FORMAT_DARK
Sets the color of the dark modules of the format information.
See :option:`--dark` for a description of allowed values.
.. option:: --format-light FORMAT_LIGHT
Sets the color of the light modules of the format information.
See :option:`--dark` for a description of allowed values.
```
--------------------------------
### XBM and XPM Serialization
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Adds support for serializing QR Codes into XBM (X BitMap) and XPM (X PixMap) formats. XBM supports black and white images, while XPM supports colors and transparency.
```python
import segno
qrcode = segno.make_qr('Hello XBM')
qrcode.save('hello.xbm')
qrcode_color = segno.make_qr('Hello XPM')
qrcode_color.save('hello.xpm', scale=5)
```
--------------------------------
### QR Code Serialization to PNG
Source: https://github.com/heuer/segno/blob/master/docs/command-line.rst
Serializes the QR code to a PNG file. The output filename is specified using the --output flag.
```bash
$ segno --output=white-room.png "White Room"
```
--------------------------------
### CLI Shortcut for Border
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Introduces the '-b' shortcut to Segno's command line interface, which provides the border or quiet zone value for the generated QR code.
```bash
# Generate QR code with a border of 5 units
segno --border 5 "QR Code"
segno -b 5 "QR Code"
```
--------------------------------
### Basic QR Code Output to Terminal
Source: https://github.com/heuer/segno/blob/master/docs/command-line.rst
Generates a QR code for the provided text and displays it directly in the terminal.
```bash
$ segno "Little wing"
```
--------------------------------
### Segno CLI Shortcut for Version
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Adds a shortcut '-V' to Segno's command line script to display version information, complementing the existing '--ver' flag.
```bash
# Display Segno version using the shortcut
segno -V
```
--------------------------------
### CLI Encoding Options
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Distinguishes between SVG document encoding and QR code encoding. Introduces `--svgencoding` for specifying SVG document encoding.
```cli
CLI ``--encoding`` was used for the encoding of SVG documents and not
for the encoding of the QR code.
Added ``--svgencoding`` to specify the encoding of SVG documents.
```
--------------------------------
### Type Hint Support
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Added support for type hints in the public API, including the provision of stub files for better static analysis and developer experience.
```python
* Added support for type hints for the public API (stub files)
```
--------------------------------
### Encoding and Helper Function Updates
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Fixes an issue with `helpers.make_epc_qr` regarding encoding specification, allowing it to be provided by name or numeric constant. Also notes the removal of the `version` parameter from `encoder.prepare_data` as it was not part of the public API.
```python
* Fixed `#72 `_:
Encodings for ``helpers.make_epc_qr`` may be specified by name or
by a numeric constant.
```
```python
* Removed "version" parameter from ``encoder.prepare_data`` (does not belong to
the public API anyway)
```
--------------------------------
### Micro QR Code Output to Terminal
Source: https://github.com/heuer/segno/blob/master/docs/command-line.rst
Generates a Micro QR code for the provided text and displays it in the terminal. Requires the --micro flag.
```bash
$ segno --micro "Little wing"
```
--------------------------------
### Segno API: Terminal Output
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Introduces an option to print QR codes in a more compact manner directly to the terminal, enhancing usability for command-line users.
```python
# Added option to print QR codes in a more compact manner to the terminal.
```
--------------------------------
### Finder Pattern Color Handling
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Fixes an issue where dark/light modules of the finder pattern might be misinterpreted when set to `None`.
```python
* Fixed `#71 `_: Dark / light
modules of the finder pattern may be interpreted wrong if set to ``None``
```
--------------------------------
### PyQRCode Comparison
Source: https://github.com/heuer/segno/blob/master/docs/comparison-qrcode-libs.rst
A note on the exclusion of PyQRCode from performance comparisons due to a lack of updates and feature parity over the past six years. Segno is presented as a more actively maintained alternative.
```text
The comparison included PyQRCode in all years before 2022. In the meantime,
six years have passed without any updates and PyQRCode has lost its connection in
many aspects.
Although popular, it lost all feature and performance comparisons, therefore it
is no longer part of this comparison.
```
--------------------------------
### Segno PNG Serializer Options
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Describes the evolution of the PNG serializer in Segno, including the addition of support for multiple colors per module type and the removal of the `addad` interpretation. The ability to specify colors for individual module types enhances the visual customization of PNG QR codes.
```APIDOC
PNG Serializer Features:
- Multiple Colors: Allows specifying distinct colors for each module type (e.g., dark modules, light modules, finder patterns).
Example:
qr.save('qrcode.png', dark='red', data_light='yellow', finder_pattern_dark='blue')
- `addad` Interpretation Removed: The interpretation of `addad` in the PNG serializer has been removed to align with the goal of creating small images by default. The option still exists in the function signature but will be removed in release 0.4.0.
- `--no-ad` CLI Option: The `--no-ad` option for the CLI is ignored and will be removed in release 0.4.0.
```
--------------------------------
### Compact QR Code Output to Terminal
Source: https://github.com/heuer/segno/blob/master/docs/command-line.rst
Generates a QR code using a more compact representation for terminal output.
```bash
$ segno --compact "Little wing"
```
--------------------------------
### Basic SVG Generation
Source: https://github.com/heuer/segno/blob/master/docs/svg-options.rst
Demonstrates how to create a QR code and save it as an SVG file with a specified scale.
```python
import segno
qrcode = segno.make('Penny Lane', error='h')
qrcode.save('penny-lane.svg', scale=4)
```
--------------------------------
### segno Command Line Script Updates
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Details updates to the segno command-line script, including new options, renamed options, and changes to default values. Covers options for error correction boosting, output format, and data encoding.
```APIDOC
--no-error-boost
- Disables error correction level incrementation.
--mode / -m
- Specifies the encoding mode.
--pattern / -p
- Specifies the mask pattern (renamed from --mask / -m).
--no-ad
- Omits the 'Software' comment in PNG images.
```
--------------------------------
### Save QR Code to Multiple Formats
Source: https://github.com/heuer/segno/blob/master/docs/make.rst
Demonstrates how to create a QR code from text and save it to different file formats like SVG, PNG, EPS, and TXT using the Segno library.
```python
import segno
qrcode = segno.make('Henry Lee')
qrcode.save('henry-lee.svg') # SVG document
qrcode.save('henry-lee.png') # PNG image
qrcode.save('henry-lee.eps') # EPS document
qrcode.save('henry-lee.txt') # Text output
```
--------------------------------
### Combine URL Background and BytesIO Output
Source: https://github.com/heuer/segno/blob/master/docs/artistic-qrcodes.rst
Shows how to use a URL for the background image and save the resulting QR code to a BytesIO stream, avoiding file system writes. Requires the 'qrcode-artistic' plugin.
```python
import io
from urllib.request import urlopen
import segno
qrcode = segno.make('The Beatles', error='h')
url = 'https://media.giphy.com/media/mUPQmck5YEisg/giphy.gif'
bg_file = urlopen(url)
out = io.BytesIO()
qrcode.to_artistic(background=bg_file, target=out, scale=5, kind='gif')
```
--------------------------------
### segno.QRCode API Changes and Enhancements
Source: https://github.com/heuer/segno/blob/master/CHANGES.rst
Documents API changes and enhancements to the segno.QRCode class, including method signature updates, deprecations, and new functionalities. Covers changes to error correction level boosting and matrix iteration.
```APIDOC
QRCode.matrix_iter(scale=1, border=None)
- Replaces QRCode.matrix_iter(border).
- Parameters:
- scale: Scaling factor for the matrix.
- border: Width of the border around the QR code.
boost_error=False
- Disables the feature to automatically increase the error correction level if it fits.
QRCode.save()
- Replaces deprecated methods eps, svg, png, pdf, and txt for saving QR codes in different formats.
```