Giter Site home page Giter Site logo

oudon / rmqrcode-python Goto Github PK

View Code? Open in Web Editor NEW
146.0 5.0 14.0 224 KB

Rectangular Micro QR Code (rMQR Code) Generator in Python

Home Page: https://pypi.org/project/rmqrcode/

License: Other

Python 99.71% Makefile 0.29%
qrcode qrcode-generator rmqrcode rmqrcode-generator

rmqrcode-python's Introduction

Rectangular Micro QR Code (rMQR Code) Generator

repo-url-rmqr-code

The rMQR Code is a rectangular two-dimensional barcode. This is easy to print in narrow space compared to conventional QR Code. This package can generate an rMQR Code image. This is implemented based on ISO/IEC 23941: Rectangular Micro QR Code (rMQR) bar code symbology specification.

pytest PyPI PyPI - Python Version PyPI - Downloads

๐ŸŽฎ Online Demo Site

You can try this online: https://rmqr.oudon.xyz .

๐Ÿ“Œ Notice

  • To read rMQR code, we can use QRQR app. However many other QR code readers may have not been supported yet.
  • Please verify an image generated by this software whether it can decode correctly before use.

๐Ÿš€ Installation

pip install rmqrcode

๐Ÿ“• Basic Usage

CLI

Generate an rMQR Code image from your command line, use rmqr command:

rmqr "Text data" "my_qr.png"

See the help to list the options:

โžœ rmqr -h
usage: rmqr [-h] [--ecc {M,H}] [--version VERSION] [--fit-strategy {min_width,min_height,balanced}]
            DATA OUTPUT

positional arguments:
  DATA                  Data to encode.
  OUTPUT                Output file path

optional arguments:
  -h, --help            show this help message and exit
  --ecc {M,H}           Error correction level. (default: M)
  --version VERSION     rMQR Code version like 'R11x139'.
  --fit-strategy {min_width,min_height,balanced}
                        Strategy how to determine rMQR Code size.

Generate rMQR Code in scripts

Alternatively, you can also use in python scripts:

from rmqrcode import rMQR
import rmqrcode

data = "https://oudon.xyz"
qr = rMQR.fit(
    data,
    ecc=rmqrcode.ErrorCorrectionLevel.M,
    fit_strategy=rmqrcode.FitStrategy.MINIMIZE_WIDTH
)

The ecc parameter is an enum value of rmqrcode.ErrorCorrectionLevel to select error correction level. The following values are available:

  • ErrorCorrectionLevel.M: Approx. 15% Recovery Capacity.
  • ErrorCorrectionLevel.H: Approx. 30% Recovery Capacity.

The fit_strategy parameter is enum value of rmqrcode.FitStrategy to specify how to determine size of rMQR Code. The following values are available:

  • FitStrategy.MINIMIZE_WIDTH: Try to minimize width.
  • FitStrategy.MINIMIZE_HEIGHT: Try to minimize height.
  • FitStrategy.BALANCED: Try to keep balance of width and height.

Here is an example of images generated by each fit strategies for data Test test test: Example of fit strategies

Save as image

from rmqrcode import QRImage

image = QRImage(qr, module_size=8)
image.show()
image.save("my_qr.png")

๐Ÿ“™ Advanced Usage

Select rMQR Code size manually

To select rMQR Code size manually, use rMQR() constructor.

from rmqrcode import rMQR, ErrorCorrectionLevel
qr = rMQR('R11x139', ErrorCorrectionLevel.H)

R11x139 means 11 rows and 139 columns. The following table shows available combinations.

27 43 59 77 99 139
R7 โŒ โœ… โœ… โœ… โœ… โœ…
R9 โŒ โœ… โœ… โœ… โœ… โœ…
R11 โœ… โœ… โœ… โœ… โœ… โœ…
R13 โœ… โœ… โœ… โœ… โœ… โœ…
R15 โŒ โœ… โœ… โœ… โœ… โœ…
R17 โŒ โœ… โœ… โœ… โœ… โœ…

Encoding Modes and Segments

The rMQR Code has the four encoding modes Numeric, Alphanumeric, Byte and Kanji to convert data efficiently. We can select encoding mode for each data segment separately. The following example shows how to encode data "123Abc". The first segment is for "123" in the Numeric mode. The second segment is for "Abc" in the Byte mode. We can select an encoding mode by passing the encoder_class argument to the rMQR#add_segment method. In this example, the length of bits after encoding is 47 in the case combined with the Numeric mode and the Byte mode, which is shorter than 56 in the Byte mode only.

from rmqrcode import rMQR, ErrorCorrectionLevel, encoder
qr = rMQR('R7x43', ErrorCorrectionLevel.M)
qr.add_segment("123", encoder_class=encoder.NumericEncoder)
qr.add_segment("Abc", encoder_class=encoder.ByteEncoder)
qr.make()

The value for encoder_class is listed in the below table.

Mode Value of encoder_class Characters
Numeric NumericEncoder 0-9
Alphanumeric AlphanumericEncoder 0-9 A-Z \s $ % * + - . / :
Byte ByteEncoder Any
Kanji KanjiEncoder from 0x8140 to 0x9FFC, from 0xE040 to 0xEBBF in Shift JIS value

Optimal Segmentation

The rMQR.fit method mentioned above computes the optimal segmentation. For example, the data "123Abc" is divided into the following two segments.

Segment No. Data Encoding Mode
Segment1 123 Numeric
Segment2 Abc Byte

In the case of other segmentation like "123A bc", the length of the bit string after encoding will be longer than the above optimal case.

๐Ÿค Contributing

Any suggestions are welcome! If you are interesting in contributing, please read CONTRIBUTING.

๐Ÿ“š References


The word "QR Code" is registered trademark of DENSO WAVE Incorporated.
http://www.denso-wave.com/qrcode/faqpatent-e.html

rmqrcode-python's People

Contributors

ar-ray-code avatar kianmeng avatar kikuchan avatar oudon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rmqrcode-python's Issues

unknown file extension: .png

with space:

C:\Users\SYM\Pictures>rmqr 'github.com/PixelSymbols' 'github profile.png'
usage: rmqr [-h] [--ecc {M,H}] [--version VERSION] [--fit-strategy {min_width,min_height,balanced}] DATA OUTPUT
rmqr: error: unrecognized arguments: profile.png'

Without space

C:\Users\SYM\Pictures>rmqr 'github.com/PixelSymbols' 'github_profile.png'
Traceback (most recent call last):
  File "C:\Users\SYM\AppData\Local\Programs\Python\Python312\Lib\site-packages\PIL\Image.py", line 2415, in save
    format = EXTENSION[ext]
             ~~~~~~~~~^^^^^
KeyError: ".png'"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\SYM\AppData\Local\Programs\Python\Python312\Scripts\rmqr.exe\__main__.py", line 7, in <module>
  File "C:\Users\SYM\AppData\Local\Programs\Python\Python312\Lib\site-packages\rmqrcode\console.py", line 61, in main
    _save_image(qr, args.OUTPUT)
  File "C:\Users\SYM\AppData\Local\Programs\Python\Python312\Lib\site-packages\rmqrcode\console.py", line 36, in _save_image
    image.save(output)
  File "C:\Users\SYM\AppData\Local\Programs\Python\Python312\Lib\site-packages\rmqrcode\qr_image.py", line 24, in save
    self._img.save(name)
  File "C:\Users\SYM\AppData\Local\Programs\Python\Python312\Lib\site-packages\PIL\Image.py", line 2418, in save
    raise ValueError(msg) from e
ValueError: unknown file extension: .png'

The rMQR class should have quiet zone

Summary

Make the rMQR class have the quiet zone.

Background

The rMQR code is surrounded by 2X light modules called quiet zone. This is defined in the ISO/IEC 23941 6.3.10 Quiet zone. However, currently implementation of the rMQR class has no quiet zone. When we generate an image file, QRImage class adds the quiet zone. If clients use the rMQR class directly, they should add the quiet zone in client-side.

Suggestion

Make the rMQR class have the quiet zone.

Incorrect optimization

Bug in the SegmentOptimizer.

Summary

A cost computed by SegmentOptimizer is too small in Byte Mode. This bug causes invalid segmentation.

Current Behaviour

>>> qr._optimized_segments("็‚น่Œ—")
[{'data': '็‚น่Œ—', 'encoder_class': <class 'rmqrcode.encoder.byte_encoder.ByteEncoder'>}

Expected Behaviour

>>> qr._optimized_segments("็‚น่Œ—")
[{'data': '็‚น่Œ—', 'encoder_class': <class 'rmqrcode.encoder.byte_encoder.KanjiEncoder'>}

Some versions code are can't be recognized by QRQR

The codes that generated this library with version R7x77, R7x139, R9x59, R9x99, R11x43, R11x77, R11x139, R13x27, R15x99, R15x139 are could not be recognized with QRQR.

to Reproduce

  1. $ rmqr nasubi out.png --version R7x77
  2. scan out.png with QRQR

Version

  • rmqrcode: 0.3.1
  • QRQR for iOS: 3.0.29

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.