Giter Club home page Giter Club logo

pyqart's Introduction

PyQArt - QArt Python implementation

中文版 README

introduction

QArt is a method of combining QrCode of an URL with any image, which was submitted in an article writen by Russ Cox on his personal website.

An Example(come from the article):

QArt Example

This repo is Python implementation of it.

Install

pip install pyqart

Note: Support Python3 only, please make sure you are using pip of Python3.

Usage

For code reuse, I split the lib to two part. One for generate normal QrCode, another for generate QArt.

The Qr Part

Use pyqr CLI to create normal QrCode.

 pyqr -p 5 -c 102 204 255 "Hello World!" -o qr.png

The options:

  • -p for point size of QrQCode, by pixel, default is 3 pixel.
  • -c for color of point, default is black. Background color can be set with -g option, default is white.

qr code: hello world

If you want show it in terminal, just don't provide -o option:

pyqr "Hello World"

Then you will see:

qr in terminal: hello world

The actual result you will see depends on your font setting, I'm using Dejavu Sans Mono.

Yes, it is only useful for small QrCode.

Run pyqr -h for more options and their effect.

The Art Part

Use pyqart CLI to create QArt. It may take a long time, please be patient :)

This is an example that mix my blog url and my Github avatar:

pyqart -v 8 -c 102 204 255 "http://0v0.link/" photo.jpg -o qart.png

My Github avatar:

The QArt Code:

Not meet your expectations? Try -n option to pick point at random(default is pick low-contrast region pixels first):

pyqart -n -c 102 204 255 -v 8 "http://0v0.link/" photo.jpg -o qart-n.png

Still not satisfied? Use -y option to enhance the accuracy of the central region by giving up the control of the edge pixels:

-y and -n can be used at the same time, but no obvious improvement.

Note: because that -y option will only use data block, ignore error correction block,it reduce many many many calculate. It has about 30x to 100x speed up compare with no -y option case. So I strongly recommend using -y option whenever you needn't make a full picture fitting.

Use -r option to set rotation degree, The controllable data region can be changed into a horizontal area, it will make it easier to process very wide picture.

Run pyqart -h for more options and their effect.

Use it in your codes as a module

Documentation is in preparation.

Gallery

python.org(used -d option, means dithering, see help message for more info.)

github.com

bilibili.com (An ACG videos website)

Halftone and HalfArt support

Halftone support added in version 0.1.0, and I made another new method which combined Halftone and QArt, so I call it HalfArt temporarily.

Arguments for all methods

The following code shows arguments to get output image of all kind of method:

from pyqart import QArtist, QrHalftonePrinter, QrImagePrinter, QrPainter

QR_VERSION = 10
POINT_PIXEL = 3

artist = QArtist('http://www.nankai.edu.cn/', 'example.jpg', QR_VERSION)
painter = QrPainter('http://www.nankai.edu.cn/', QR_VERSION)
artist_data_only = QArtist('http://www.nankai.edu.cn/', 'example.jpg',
                           QR_VERSION, only_data=True)

# normal
QrImagePrinter.print(painter, path='normal.png', point_width=POINT_PIXEL)
# Halftone
QrHalftonePrinter.print(painter, path='halftone.png', img='example.jpg',
                        point_width=POINT_PIXEL, colorful=False)
# Halftone colorful
QrHalftonePrinter.print(painter, path='halftone-color.png', img='example.jpg',
                        point_width=POINT_PIXEL)
# Halftone pixel
QrHalftonePrinter.print(painter, path='halftone-pixel.png', img='example.jpg',
                        point_width=POINT_PIXEL, colorful=False,
                        pixelization=True)
# QArt
QrImagePrinter.print(artist, path='qart.png', point_width=POINT_PIXEL)
# QArt data only
QrImagePrinter.print(artist_data_only, path='qart-data-only.png',
                     point_width=POINT_PIXEL)
# HalfArt
QrHalftonePrinter.print(artist, path='halfart.png', point_width=POINT_PIXEL)
# HalfArt data only
QrHalftonePrinter.print(artist_data_only, path='halfart-data-only.png',
                        point_width=POINT_PIXEL)

Result example for all method

Halftone Halftone colorful Halftone pixel
QArt QArt data only
HalfArt HalfArt data only

TODO

  • Make QrPainter decided argument by itself.
  • Art part
  • CLI
  • Package
  • Halftone support
  • self-made HalfArt method
  • GUI
  • Use Cython to accelerate Reed-Solomon error correction
  • Docs
  • Tests

Other Implementation

Acknowledgements

  • All credit goes to Russ Cos, Thanks for his article and implement.
  • Thanks for qart4j project by dieforfree,which helps me so much on how to implement the art part.
  • Thanks to a series of articles named QR Code Tutorial in thonky.com, It's very detailed. Whenever I faced problem about encoding or error correction, I will go to it for help.
  • Thanks to the Python programing language。

LICENSE

MIT.

See LICENSE.

pyqart's People

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

pyqart's Issues

请教qart

您好,
我是彭昊,来自山东大学交叉研究中心。因为工作需要我现在也在研究Qart,在参照Qart4j做Qart的C++实现,不过现在还有很多不懂的地方。在GitHub上看到您已经实现了一个qart的Python版本,所以想来请教一下,问一下您方便留一个联系方式吗,或者直接联系我 [email protected].

非常感谢,
彭昊

Fix simple typo: writen -> written

Issue Type

[x] Bug (Typo)

Steps to Replicate

  1. Examine README.md.
  2. Search for writen.

Expected Behaviour

  1. Should read written.

Semi-automated issue generated by
https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

To avoid wasting CI processing resources a branch with the fix has been
prepared but a pull request has not yet been created. A pull request fixing
the issue can be prepared from the link below, feel free to create it or
request @timgates42 create the PR. Alternatively if the fix is undesired please
close the issue with a small comment about the reasoning.

https://github.com/timgates42/pyqart/pull/new/bugfix_typo_written

Thanks.

在 Windows CMD 中无法显示二维码,字符集编码有问题?

C:\Users\Solar\Desktop>pyqr "Hello World"
Traceback (most recent call last):
File "c:\python35-32\lib\runpy.py", line 184, in run_module_as_main
"main", mod_spec)
File "c:\python35-32\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "C:\Python35-32\Scripts\pyqr.exe__main
.py", line 9, in
File "c:\python35-32\lib\site-packages\pyqart\qr_entry.py", line 79, in main
QrStringPrinter.print(painter, True)
File "c:\python35-32\lib\site-packages\pyqart\qr\printer\string_printer.py", line 44, in print
print(string)
UnicodeEncodeError: 'gbk' codec can't encode character '\u2580' in position 1: illegal multibyte sequence

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.