Giter Club home page Giter Club logo

amazing-qr's Introduction

Amazing-QR

former name PyPI - Downloads PyPI - Python Version PyPI PyPI - Wheel PyPI - Downloads PyPI - License GitHub code size in bytes macos linux windows

sponsor

转到中文版

Overview

Python QR Code Generator

Generate common qr-code, artistic qr-code (black & white or colorized), animated qr-code (black & white or colorized).

Contents

Examples

Install

# via pip
pip install amzqr

Usage

Terminal Way

(TIPS: If you haven't install amzqr, you should python(3) amzqr.py instead of amzqr blow.)

# summary
amzqr Words
      [-v {1,2,3,...,40}]
      [-l {L,M,Q,H}]
      [-n output-filename]
      [-d output-directory]
      [-p picture_file]
      [-c]
      [-con contrast]
      [-bri brightness]

Common QR-Code

#1 Words
amzqr https://github.com
  • Just input a URL or a sentence, then get your QR-Code named 'qrcode.png' in the current directory.
#2 -v, -l
amzqr https://github.com -v 10 -l Q
  • The default size of QR-Code depends both on the numbers of words you input and the level, while the default level (Error Correction Level) is H (the highest).

  • Customize: If you want to control the size and the error-correction-level, use the -v and -l arguments.

    -v representing the length is from a minimum of 1 to a maximum of 40.

    -l representing the error correction level is one of L, M, Q and H, where L is the lowest level and H is the highest.

#3 -n, -d
amzqr https://github.com   -n github_qr.jpg   -d .../paths/
  • The default output-filename is 'qrcode.png', while the default output-directory is current directory.

  • Customize: You can name the output-file and decide the output-directory. Notice that if the name is as same as a existing file, the old one will be deleted.

    -n representing the output-filename could be in the format one of .jpg.png.bmp.gif .

    -d means directory.

Artistic QR-Code

#1 -p
amzqr https://github.com -p github.jpg
  • The -p is to combine the QR-Code with the following picture which is in the same directory as the program. The resulting picture is black and white by default.
#2 -c
amzqr https://github.com -p github.jpg -c
  • The -c is to make the resulting picture colorized.
#3 -con, -bri
amzqr https://github.com -p github.jpg [-c] -con 1.5 -bri 1.6
  • The -con flag changes the contrast of the picture - a low number corresponds to low contrast and a high number to high contrast. Default: 1.0.

  • The -bri flag changes the brightness and the parameter values work the same as those for -con. Default: 1.0.

Animated GIF QR-Code

The only difference from Artistic QR-Code mentioned above is that you should input an image file in the .gif format. The you can get your black-and-white or colorful qr-code. Remember that when you use -n to customize the output-filename, then the output-filename must end by .gif.

Import Way

from amzqr import amzqr

version, level, qr_name = amzqr.run(
    words,
    version=1,
    level='H',
    picture=None,
    colorized=False,
    contrast=1.0,
    brightness=1.0,
    save_name=None,
    save_dir=os.getcwd()
)

details about each parameter are as mentioned above

# help(amzqr)
Positional parameter
   words: str

Optional parameters
   version: int, from 1 to 40
   level: str, just one of ('L','M','Q','H')
   picutre: str, a filename of a image
   colorized: bool
   constrast: float
   brightness: float
   save_name: str, the output filename like 'example.png'
   save_dir: str, the output directory

Tips

  • Use a nearly square picture instead of a rectangle one.

  • If the size of the picture is large, you should also choose a rightly large -v instead of using the default one.

  • If part of the picture is transparent, the qr code will look like:

    You can change the transparent layer to white, and then it will look like:

Supported Characters

  • Numbers: 0~9

  • Letters: a~z, A~Z

  • Common punctuations:

    · , . : ; + - * / \ ~ ! @ # $ % ^ & ` ' = < > [ ] ( ) ? _ { } | and  (space)

Environment

  • Python 3

License

  • GPLv3

Buy me a coffee

GitHub Sponsors

Since the GitHub Sponsors is unavailable in China yet...

wechatpay

wechatpay

alipay

alipay

🎉🎉🎉 Thanks for your support. 🎉🎉🎉

amazing-qr's People

Contributors

alichaudry avatar dependabot[bot] avatar patrick91 avatar x-hw 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  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

amazing-qr's Issues

一个在线演示网站 支持中文英文混编 供参考

image

  1. 支持中文
  2. 支持中文英文混编

对源码做了修改, 贴出来项目地址, 供大家参考, GPLv3 协议.

项目地址: https://github.com/jwenjian/awesome-qrcode
在线演示: https://wenjian.pythonanywhere.com/

输入中文, 英文混编试试 🎉

主要修改:

  1. 将输入内容进行编码转换: utf16 -> utf8

def utf16to8(input_txt: str) -> str:
    out = []
    for idx in range(len(input_txt)):
        ch = ord(input_txt[idx])
        if 0x0001 <= ch <= 0x007f:
            out.append(input_txt[idx])
        elif ch > 0x07ff:
            out.append(chr(0xE0 | (ch >> 12 & 0x0F)))
            out.append(chr(0x80 | (ch >> 6 & 0x3F)))
            out.append(chr(0x80 | (ch >> 0 & 0x3F)))
        else:
            out.append(chr(0xC0 | (ch >> 6) & 0x1f))
            out.append(chr(0x80 | (ch >> 0) & 0x3f))

    return ''.join(out)
version, level, qr_name = myqr.run(utf16to8(text), save_name=target_filename)
  1. 去掉源代码中对输入字符的支持判断(比较暴力, 仅供参考)
    if not isinstance(words, str):
        raise ValueError('Wrong words! Words must be a str instance!')

关于保持图片清晰度

我看代码中对传入的图片是做了resize压缩处理,如果传入的图片长宽像素值比较大(但是相等),可否在不压缩的情况下生成高清的背景?

这也牵扯出另一个问题,二维码中的黑白点可否支持设置点的大小,而不是固定一个像素。

本来想自己修改修改的,但是发现代码中hardcode太多了。。

persian or unicode character support

Hi dear friend
please update your amazing code for support Arabic unicode character.

revolt@revolt:~/mywork/reconf96-QRs$ myqr ری کنفرانس -n 1.png -p nojum-trancparent.png -c -v 3
usage: myqr [-h]
[-v {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40}]
[-l {L,M,Q,H}] [-p PICTURE] [-c] [-con CONTRAST] [-bri BRIGHTNESS]
[-n NAME] [-d DIRECTORY]
Words
myqr: error: unrecognized arguments: کنفرانس

Thanks

When I use the -p option,it raise a problem

I have install the tool with pip,and this command myqr https://github.com will work. But when I use the -p option it will raise a error , a litter this issue #39 (comment).

The detailed error information is as follows:

# 1. using -p
$ myqr https://github.com -p github.jpg
Traceback (most recent call last):
  File "G:\python-3.7.1\Scripts\myqr-script.py", line 11, in <module>
    load_entry_point('MyQR==2.3.1', 'console_scripts', 'myqr')()
  File "g:\python-3.7.1\lib\site-packages\MyQR\terminal.py", line 34, in main
    args.directory
  File "g:\python-3.7.1\lib\site-packages\MyQR\myqr.py", line 36, in run
    raise ValueError("Wrong picture! Input a filename that exists and be tailed with one of {'.jpg', '.png', '.bmp', '.gif'}!")
ValueError: Wrong picture! Input a filename that exists and be tailed with one of {'.jpg', '.png', '.bmp', '.gif'}!


# 2 using -p -c
$ myqr https://github.com -p github.jpg -c
Traceback (most recent call last):
  File "G:\python-3.7.1\Scripts\myqr-script.py", line 11, in <module>
    load_entry_point('MyQR==2.3.1', 'console_scripts', 'myqr')()
  File "g:\python-3.7.1\lib\site-packages\MyQR\terminal.py", line 34, in main
    args.directory
  File "g:\python-3.7.1\lib\site-packages\MyQR\myqr.py", line 36, in run
    raise ValueError("Wrong picture! Input a filename that exists and be tailed with one of {'.jpg', '.png', '.bmp', '.gif'}!")
ValueError: Wrong picture! Input a filename that exists and be tailed with one of {'.jpg', '.png', '.bmp', '.gif'}!

I think the option -p has some problem.

print("line 16: mode: byte") is in the way on servers

If you are using this on the server then you might get a problem with the print("line 16: mode: byte") part if you don't want to fork the repo to fix it you can monkey patch the print() function like this.

import os
from MyQR import myqr
import builtins


def custom_print(*args, **kwargs):
    pass


print("print called")
original_print = print
builtins.print = custom_print
print("now print is also called but should not show up")


version, level, qr_name = myqr.run(
    "https://somesite.eu",
    version=1,
    level='H',
    picture='./tmp/lab.gif',
    colorized=True,
    contrast=1.0,
    brightness=1.0,
    save_name='tmp/labout.gif',
    save_dir=os.getcwd()
)
builtins.print = original_print
print("now print should also show up agian")

Import Way

Hello:

I'm probably doing something wrong, so I'm getting lots of syntax errors.
Where is what I did. I switched to MyQR dir and executed python myqr.py.
I'm trying to test the import way but I don't know exactly how to do that. Can you give a more specific example?
Once I'm in terminal I type from MyQR import myqr and so on, but I'm not sure where do I insert my filename and which output I will have from that. I'm new to python.

Best Regards,
Gabriela

_qrcode2.default is not a constructor

组件中的引入方式: import QRCode from 'qrcode'
js代码: show() {
let qrcode = new QRCode(document.getElementById('pwdBox'), {
width: 96, // 设置宽高
height: 96,
})
qrcode.makeCode('abcdefghijklmn')
},
报错: _qrcode2.default is not a constructor
at VueComponent.getCode (intelligent-key.js:3529)
at boundFn (vendor.js:4901)
at HTMLDivElement.invoker (vendor.js:6470)
请问这个问题该怎么解决?

不支持支付宝和微信二维码的链接?

WARNING: Input Error! Please read the README file for the supported characters!!

然而链接里没发现数字、英文字母和常用标点之外的字符啊。

注:是扫一扫付款的二维码

网上找的相关的中文等编码处理

from MyQR import myqr

def utf16to8(str):
out = []
for idx in range(len(str)):
ch = ord(str[idx])
if ch >= 0x0001 and ch <= 0x007f:
out.append(str[idx])
elif ch > 0x07ff:
out.append(chr(0xE0 | (ch >> 12 & 0x0F)))
out.append(chr(0x80 | (ch >> 6 & 0x3F)))
out.append(chr(0x80 | (ch >> 0 & 0x3F)))
else:
out.append(chr(0xC0 | (ch >> 6) & 0x1f))
out.append(chr(0x80 | (ch >> 0) & 0x3f))

return ''.join(out)

if name == 'main':
print(utf16to8('你好'))
myqr.run(utf16to8('ਹੈਲੋ'))

Artistic QR-Code

About Artistic QR-Code I can't make QR code combine with an image.
A error mess is displayed :
"Traceback (most recent call last):
File "C:\Python36\Scripts\myqr-script.py", line 11, in
load_entry_point('MyQR==2.3.1', 'console_scripts', 'myqr')()
File "c:\python36\lib\site-packages\MyQR\terminal.py", line 34, in main
args.directory
File "c:\python36\lib\site-packages\MyQR\myqr.py", line 36, in run
raise ValueError("Wrong picture! Input a filename that exists and be tailed with one of {'.jpg', '.png', '.bmp', '
}!")
ValueError: Wrong picture! Input a filename that exists and be tailed with one of {'.jpg', '.png', '.bmp', '.gif'}!"
So can you tell me where I should put an image to make QR code.
Thank you so much.

求熊本熊的GIF文件

本不该出现在这的事情,跪求熊本熊的GIF文件(无二维码的)。
多谢!

二维码生成规则

为什么有的二维码马眼很多,有的很少,是链接长短还是链接出现的不重复字符多少控制的?

Exception when encoding a single character

version, level, qr_name = myqr.run(
        'A',
        level='H',
        colorized=False,
        contrast=1.0,
        brightness=1.0,
        save_name='testing.png',
        save_dir='barcodes'
)
Traceback (most recent call last):
  File "/.ta_venv/lib/python3.6/site-packages/MyQR/myqr.py", line 94, in run
    ver, qr_name = theqrmodule.get_qrcode(version, level, words, tempdir)
  File "/.ta_venv/lib/python3.6/site-packages/MyQR/mylibs/theqrmodule.py", line 10, in get_qrcode
    ver, data_codewords = data.encode(ver, ecl, str)
  File "/.ta_venv/lib/python3.6/site-packages/MyQR/mylibs/data.py", line 18, in encode
    code = mode_indicator[mode] + get_cci(ver, mode, str) + mode_encoding[mode](str)
  File "/.ta_venv/lib/python3.6/site-packages/MyQR/mylibs/data.py", line 84, in alphanumeric_encoding
    if i != len(code_list) - 1:
UnboundLocalError: local variable 'i' referenced before assignment

art qrcode no same play time when the picture is a .gif file

Thanks for the amazing qrcode tools first, but meet a problem:

I get a art qrcode after use the tool builds with a gif picture, but it plays faster than origin gif picture. So how to set the art qrcode play speed as fast as origin picture?

thanks in ahead

请问可以限定生成图片的尺寸吗?

请问可以限定生成图片的尺寸吗?

我试着修改word的内容,根据不同的内容,生成的图片大小也不一样。 不知道是否可以增加size属性。。。
当然 限定size的话, 传入的图片也会配合好的, 比如计划生成200x200 那么就传个背景图也是200x200的

谢谢。

怎么可以不支持双引号"呢

就差双引号了。
用3个双引号就可以把1个双引号括起来了。哪位顺手改一下吧:)
supported_chars = r"""something"""

import string
sup_set = set(supported_chars)
pri_set = set(string.printable)
sup_set - pri_set # output: {'·'}
pri_set - sup_set # output: {'\t', '\x0c', '\x0b', '\r', '"', '\n'}

关于生成wifi连接怎么成功生成?

那个,如何才生成可以扫码后可链接Wifi的二维码呐?

WIFI:T:WPA;P:"Routing",S:password;

如果引起来,那会变成文本,但不引起来又无法生成……

关于换行符

如果我不是输入URL而是输入一段文本,文本中存在换行符的话会报错

A dependency-free executable

Can you package this program into a self-contained program (maybe via PyInstaller) so user don't have to install dependencies. I was blocked on decencies installation when I wanted to try it.

使用时报错。

python myqr.py http://weixin.qq.com/r/PUgrM0TEzBmzrQBQ9xxx -p aaa.jpg

Traceback (most recent call last):
  File "myqr.py", line 72, in <module>
    ver, qr_name = theqrmodule.get_qrcode(ver, ecl, args.WORDs, save_place)
  File "/xxxx/qrcode-master/mylibs/theqrmodule.py", line 29, in get_qrcode
    qrmatrix = matrix.get_qrmatrix(ver, ecl, final_bits)
  File "/xxxx/qrcode-master/mylibs/matrix.py", line 45, in get_qrmatrix
    place_bits(bits, qrmatrix)
  File "/xxxx/qrcode-master/mylibs/matrix.py", line 106, in place_bits
    m[i][j] = next(bit)
StopIteration

微信链接有问题.

tempdir的做法导致处理并行任务的时候出错

tempdir='~/.myqr/'会在开始的时候创建,最后删除,如果一台机器上有多个process在使用这个library,就会出现process A刚创建完,还没有生成好图片,process B就把该目录删除了,解决方案可以是把save_name也放到tempdir的目录名字上 或者不用时"~"是在save_dir里面创建临时目录:
tempdir = os.path.join(os.path.expanduser('~'), '.myqr', save_name)
or
tempdir = os.path.join(save_dir, '.myqr', save_name)
你看看是否可以,如果可以就更新一下library,谢谢了

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.