heuer / segno Goto Github PK
View Code? Open in Web Editor NEWPython QR Code and Micro QR Code encoder
Home Page: https://pypi.org/project/segno/
License: BSD 3-Clause "New" or "Revised" License
Python QR Code and Micro QR Code encoder
Home Page: https://pypi.org/project/segno/
License: BSD 3-Clause "New" or "Revised" License
See #16: add option to set boost_error to False
>>> from segno import *
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from segno import *
TypeError: Item in ``from list'' must be str, not unicode
The SVG writer has a lot of options but the command line script supports just a subset (color, background, scale, border). It should support all SVG options, though
This library is very well done:
It should be the default choice for QR handling in Python. Just wanted to say thanks for the hard work :)
I would be nice to add the photo field to the vcard
https://tools.ietf.org/html/rfc6350#section-6.2.4
Examples:
PHOTO:http://www.example.com/pub/photos/jqpublic.gif
PHOTO:data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhv
AQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bm
ljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0
<...remainder of base64-encoded data...>
This allows files of data to be represented logically and continuously in up to 16 QR Code symbols. These may be scanned in any sequence to enable the original data to be correctly reconstructed. (c.f. chapter 8)
Minor priority since the usual QR Code readers do not support this mode; might be a "nice to have"
content has a default value: '' (empty string). Default should be undefined
Maybe useful for decoding (not planned yet) http://www.datagenetics.com/blog/november12013/
>>> import segno
>>> from segno import writers
>>> qr = segno.make('test')
>>> qr.designator
'M3-M'
>>> qr.mask
3
>>> writers.write_svg_debug(qr.matrix, qr._version, 'issue-3.svg')
if is_micro:
if not 0 <= mask <= 4:
raise MaskError('Invalid data mask "{0}" for Micro QR Code'.format(mask))
else:
if not 0 <= mask <= 8:
raise MaskError('Invalid data mask "{0}"'.format(mask))
Correct: 0 <= mask < 4
and 0 <= mask < 8
Would be nice if plugins and their specific keywords could be supported:
$ segno 'Cocaine' --plugin=glow deviation=.4 filter-id=boah -o=cocaine.svg
Thank's for your work.
Is it possible to know all the different vcard fields we can introduce with segno? on segno.readthedocs.io, I only see the following parameters :
qr = helpers.make_vcard(name='Doe;John', displayname='John Doe', email='[email protected]', phone='+1234567')
but there are many others parameters :
https://en.wikipedia.org/wiki/VCard#Properties
The SVG writer serializes unit=None as ... height="None" which is wrong. The unit should be omitted and the result should be: height="" without any unit indicator
test_pbm.py / line 54 ...
if l.startswith(b'P') or l.startswith(b'#'):
print('Skip line', l)
continue
I use onlinebarcodereader to decode the qrcode that generate by segno and I find it always auto append '0a' to the content in hex values. How to remove it?
Error:
default_color = struct.unpack("hhhhHhhhhhh", csbi.raw)[4]
TypeError: Struct() argument 1 must be string, not unicode
Solution:
writers.py / line 770
default_color = struct.unpack(b'hhhhHhhhhhh', csbi.raw)[4]
The factory functions of helpers.py
aren't accessible through the command line script; might be useful to find a way to expose them.
segno wifi network=x password=y
Probably it might be more useful to utilize the make_XXX_data
factories since the command line script could set the error level and QR Code version
If setting the svgid, svgclass or lineclass to '', the attribute must be serialized.
If the user specifies the version but not the error level, a DataOverflowException may be raised
>>> import segno
>>> qr = segno.make('Wikipedia', version='M3')
Traceback (most recent call last):
[...]
DataOverflowError: The provided data does not fit into version "M3". Proposal: version M4
If Segno would not insist on error level M (default), the symbol can be generated:
>>> import segno
>>> qr = segno.make('Wikipedia', version='M3', error='l')
>>> qr.designator
'M3-L'
The mask pattern evaluation step can be skipped if the user provides a mask.
if proposed_mask is not None:
# apply mask
return matrix, proposed_mask
for mask_name, mask_pattern ....
# Apply mask, evaluate, etc.
Would be nice if Segno could be used as Inkscape extension.
Maybe a subproject?
Since Windows does not support ANSI escape codes, the user gets garbage.
Tested with Win 8.
TODO: Test with Windows 10 since it should support ANSI escape sequences
>>> import segno
>>> qr = segno.make('http://www.example.org/bla/bla/')
>>> qr.show() # Does not scan
>>> qr.designator
'3-H'
>>> qr = segno.make('http://www.example.org/bla/bla/', boost_error=False)
>>> qr.show() # Works!
>>> qr.designator
'3-M'
>>> # Setting the error level to 'H' works, too
>>> qr = segno.make('http://www.example.org/bla/bla/', error='h')
>>> qr.show() # Works!
>>> qr.designator
'4-H'
>>> # boost_error should choose error level "Q" which does not change the QR Code version
>>> qr = segno.make('http://www.example.org/bla/bla/', boost_error=False, error='q')
>>> qr.show() # Works!
>>> qr.designator
'3-Q'
Segno supports EPS and SVG. Is the PDF output useful at all? Maybe it should become a plugin.
helpers.make_email_data
uses :
as delimiter for CC / BCC values; =
must be used.
The algorithm in add_codewords
starts with the upper right corner instead of the bottom right corner to add codewords to the matrix. This happens for M1 and M3, only
See also #33
Maybe some example images would enhance the docs, see heuer/segno-mimos#2
Hi,
I was trying to generate some micro QR codes that should be read by someone else, but they reported that they could not read them.
After some investigation, it seems that the code for generating format information for micro QR codes is wrong, except for M1 and M2-L code.
The patch below seems to fix that problem, although the people who read my codes still report they can’t read the M3 codes I generated (M2 and M4 seemed to be fine)…
Cheers,
--
Nicolas Boullis
diff --git a/segno/encoder.py b/segno/encoder.py
--- a/segno/encoder.py
+++ b/segno/encoder.py
@@ -786,12 +786,15 @@ def add_format_info(matrix, version, err
is_micro = version < 1
offset = int(is_micro)
fmt = mask_pattern
- if error == consts.ERROR_LEVEL_L:
- fmt += (0x08 if not is_micro else 0x4)
- elif error == consts.ERROR_LEVEL_H:
- fmt += (0x10 if not is_micro else 0xe)
- elif error == consts.ERROR_LEVEL_Q:
- fmt += (0x18 if not is_micro else 0x14)
+ if is_micro:
+ fmt += consts.ERROR_LEVEL_TO_MICRO_MAPPING[version][error] << 2
+ else:
+ if error == consts.ERROR_LEVEL_L:
+ fmt += 0x08
+ elif error == consts.ERROR_LEVEL_H:
+ fmt += 0x10
+ elif error == consts.ERROR_LEVEL_Q:
+ fmt += 0x18
format_info = consts.FORMAT_INFO[fmt] if not is_micro else consts.FORMAT_INFO_MICRO[fmt]
for i in range(8):
bit = (format_info >> i) & 0x01
Segno could accept something like
>>> import segno
>>> segno.make('Avalanche', error=.07)
>>> segno.make('Tupelo', error=.25)
where the error value refers to the corresponding error levels "L", "M", "Q", "H".
PyQRCode, for example, accepts values like "7%" etc.
I don't think that PyQRCode's behaviour adds any value, maybe
>>> segno.make('Mermaids', error=7)
>>> segno.make('Deanna', error=25)
would make more sense.
If it makes sense at all...
>>> from segno import xxx
>>> geo_qr = xxx.from_geo(lat=38.8976763, lang=-77.0365297)
>>> bookmark_qr = xxx.from_bookmark('http://www.example.org/')
>>> wifi_qr = xxx.from_wifi(ssid='network', password='admin', type='wpa')
[...]
Would be nice if CLI would not show the traceback but simply return an error code and show the message from the exception
$ segno --micro This does not fit into a micro code
Traceback (most recent call last):
[...]
segno.encoder.DataOverflowError: Data too large. No Micro QR Code can handle the provided data
Optimize input acc. to ISO/IEC 18004:2015(E) Annex J
>>> from segno import encoder
>>> qr = encoder.encode(0)
>>> # Expect M1
>>> encoder.get_version_name(qr.version)
'M2'
>>> qr.error is None
False
The SVG serializer uses the version attribute to determine if CSS3 colors can be used. The SVG document gets a version attribute iff version is not None
.
Acc. to https://www.w3.org/TR/SVG2/struct.html#SVGElement (W3C Candidate Recommendation dtd. 15 September 2016) the version attribute has been removed from SVG 2. The writer must not add it to the document if version == 2.0
The helpers
module provides several factory functions to create QR Codes for e-mail addresses, contacts, ...
Might be nice if at least the make_XXX (and not make_XXX_data) functions would be available with a simple import segno
import:
Currently:
>>> from segno import helpers
>>> qr = helpers.make_email('[email protected]')
If segno.__init__
imports the factory functions:
>>> import segno
>>> qr = segno.make_email('[email protected]')
The factory functions of helpers
differ from the usual factory functions, though. They don't allow to set the minimum error level / version ...
segno --segno-version
segno --ver
...
--version is taken (specify QR Code version)
--h should mention the version as well
Update the test suite. Currently 1166 pytest-warnings
yield-based test cases will be removed in pytest 4.0
encoder.find_version
takes the character count (len(data)
) and the individual modes into account. This may lead to suboptimal versions. find_version
should take the number of bits into account. Further, it should take the overhead (mode indicator, length of char indicator) into account, see TODO.
Would be nice if a minimum error level could be provided. If the data is small enough, the algorithm could increase the error level automatically (version must be the same).
>>> import segno
>>> qr_m = segno.make_qr('ABCDE', error='m')
>>> qr_m.designator
'1-M'
>>> qr_h = segno.make_qr('ABCDE', error='h')
>>> q_h.designator
'1-H'
>>> qr_h.symbol_size() == qr_m_symbol_size()
True
The above should be done automatically, if the user wants it
>>> import segno
>>> qr = segno.make_qr('ABCDEF', please_increase_error_level_if_possible=True)
>>> qr.designator
'1-H'
>>> # With an explicit error level
>>> qr = segno.make_qr('ABCDEF', error='l', please_increase_error_level_if_possible=True)
>>> qr.designator
'1-H'
Caution: "mask" uses already "m". Rename "mask" into "pattern" and use "p"?
>>> import segno
>>> qr = segno.make('')
>>> qr.version
'M3'
>>> qr.mode
'byte'
Shouldn't we expect version "M1" in "alphanumeric" mode?
Does not work:
segno --scale 10 --output good-times.png Good Times
usage: segno [-h] [--version VERSION] [--error {L,M,Q,H,-}]
[--mode {numeric,alphanumeric,byte,kanji}] [--pattern PATTERN]
[--scale SCALE] [--border BORDER] [--micro] [--no-micro]
[--color COLOR] [--background BACKGROUND] [--output OUTPUT]
[--no-error-boost] [--no-classes] [--no-xmldecl] [--no-namespace]
[--no-newline] [--title TITLE] [--desc DESC] [--svgid SVGID]
[--svgclass SVGCLASS] [--lineclass LINECLASS] [--no-size]
[--unit UNIT] [--svgversion SVGVERSION] [--encoding ENCODING]
[--dpi DPI] [--no-ad] [--ver]
content
segno: error: unrecognized arguments: Times
Works:
segno --scale 10 --output good-times.png "Good Times"
I can not set error corr. Level to M if I ser version to 15. I need both values. How can I di this?
Great!!! https://github.com/sylnsfar/qrcode
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.