quirc 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +30 -0
- data/lib/quirc.rb +4 -0
- data/lib/quirc/version.rb +1 -1
- data/test/fixtures/hello.gz +1 -0
- data/test/helper.rb +7 -0
- data/test/test_decode.rb +24 -1
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75f339f3801cedf03f79764d97d4d2fc0f7455fe63a390ab0894dd5894762eb5
|
|
4
|
+
data.tar.gz: ab831c1fdd0d0ed4fb6ac4fc04d2abe5b2950aff089e3155149a4e2687c783dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 409400fac11aafee4ed04e5ad57f9e89c4f1a270a7c33ffa4ed8d7569b0dd1f64f49d4627dec4b31a9c8e2ca3d323715eea93a35d7f7b227f63b920464a653cc
|
|
7
|
+
data.tar.gz: 7692bc1e8f75cc18d0b9fd70a7f77432d23f2d50ee09ee063e27a8f7641fda806d84a988f6d12f9916d28cf342cb4680f0caea01e3df117aad05ef1ba1b3a224
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -3,5 +3,35 @@
|
|
|
3
3
|
[Quirc](https://github.com/dlbeer/quirc) is a small C library for extracting and decode QR codes from images.
|
|
4
4
|
This project is a Ruby binding for that library with the library embedded.
|
|
5
5
|
|
|
6
|
+
## Example
|
|
7
|
+
You have to supply a [ChunkyPNG](http://chunkypng.com/) object or a binary string of the grayscale image with width and height.
|
|
8
|
+
```ruby
|
|
9
|
+
require 'chunky_png'
|
|
10
|
+
require 'quirc'
|
|
11
|
+
|
|
12
|
+
img = ChunkyPNG::Image.from_file('path_to_image.png')
|
|
13
|
+
res = Quirc.decode(img).first
|
|
14
|
+
puts res.payload
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'base64'
|
|
19
|
+
require 'zlib'
|
|
20
|
+
require 'quirc'
|
|
21
|
+
|
|
22
|
+
encoded = <<~EOD
|
|
23
|
+
eJzt0kEOwyAMRNHe/9LpFo1mwK1IYqQ/mwQDfl5wXYQQQgghT+cziZ7Tb+Ue
|
|
24
|
+
7vvurL76Vvvhvuvqu0jvqHoP9wx3dh73fHdWxz3Hrc5TvYfbx01RP83j7uH2
|
|
25
|
+
cCtzuf+7g7uvr74ZrY9r967cedxebrrjZtK9tMbt4Y7+L/V/Tdzn3DRH+td5
|
|
26
|
+
0hq3h5veR+qjNTcPbh+3Mpd7Qzt6497vat+Voe9Oa7j93GpdrXGt+7i9XO3j
|
|
27
|
+
+jknzYB7huvmGM+7GXHPcWeOM3B7upV5Rlvvun3cHm6K+qt5qibucy4hhBBC
|
|
28
|
+
yN58AXWDGDc=
|
|
29
|
+
EOD
|
|
30
|
+
|
|
31
|
+
img = Zlib::Inflate.inflate(Base64.decode64(encoded))
|
|
32
|
+
res = Quirc.decode(img, 44, 44).first
|
|
33
|
+
puts res.payload
|
|
34
|
+
```
|
|
35
|
+
|
|
6
36
|
## License
|
|
7
37
|
This software is licensed under the MIT License. [View the license](LICENSE).
|
data/lib/quirc.rb
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
module Quirc
|
|
4
4
|
def self.decode(image, width=nil, height=nil)
|
|
5
|
+
unless image.respond_to?(:to_grayscale_stream) || (width && height)
|
|
6
|
+
raise ArgumentError, "Arguments width and height are required if binary string is passed"
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
width ||= image.public_send(:width)
|
|
6
10
|
height ||= image.public_send(:height)
|
|
7
11
|
if image.respond_to?(:to_grayscale_stream)
|
data/lib/quirc/version.rb
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
x���A� D������f��Hb�?�~^p]�B!O�3���o����V����H�z�wv�|wV�=ǭ�S����MQ?�����p+s����������k���y�^n��fҽ�����/�M���4G��y�����G�57n�2�{C;z���jߕ��Nk���j]�q����\���9'̀{���ϻq�qg�3p{��yF[�}�n���y�&�s.!�B��|u�7
|
data/test/helper.rb
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "zlib"
|
|
4
|
+
|
|
3
5
|
require "minitest/autorun"
|
|
4
6
|
require "oily_png"
|
|
7
|
+
|
|
5
8
|
require "quirc"
|
|
6
9
|
|
|
7
10
|
module TestHelpers
|
|
11
|
+
def binary_fixture(*path)
|
|
12
|
+
Zlib::Inflate.inflate(File.binread(File.join(__dir__, "fixtures", *path)))
|
|
13
|
+
end
|
|
14
|
+
|
|
8
15
|
def image_fixture(*path)
|
|
9
16
|
ChunkyPNG::Image.from_file(File.join(__dir__, "fixtures", *path))
|
|
10
17
|
end
|
data/test/test_decode.rb
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
require "helper.rb"
|
|
4
4
|
|
|
5
5
|
describe Quirc do
|
|
6
|
+
describe "binary string" do
|
|
7
|
+
it "should decode" do
|
|
8
|
+
result = Quirc.decode(binary_fixture("hello.gz"), 120, 120).first
|
|
9
|
+
assert_equal 1, result.ecc_level
|
|
10
|
+
assert_equal "Hello World!", result.payload
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
6
14
|
describe "error levels" do
|
|
7
15
|
it "should decode all error levels" do
|
|
8
16
|
%i[m l h q].each_with_index do |level, no|
|
|
@@ -16,9 +24,24 @@ describe Quirc do
|
|
|
16
24
|
|
|
17
25
|
describe "errors" do
|
|
18
26
|
it "should throw error if image size is not equal to buffer" do
|
|
19
|
-
assert_raises ArgumentError
|
|
27
|
+
e = assert_raises ArgumentError do
|
|
20
28
|
Quirc::Decoder.new(1, 2).decode("abc")
|
|
21
29
|
end
|
|
30
|
+
assert_equal "Decoder is allocated for 1x2 images", e.message
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should throw error if width is not specified with binary string" do
|
|
34
|
+
e = assert_raises ArgumentError do
|
|
35
|
+
Quirc.decode("", nil, 1)
|
|
36
|
+
end
|
|
37
|
+
assert_equal "Arguments width and height are required if binary string is passed", e.message
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "should throw error if width height not specified with binary string" do
|
|
41
|
+
e = assert_raises ArgumentError, "Decoder is allocated for 1x2 images" do
|
|
42
|
+
Quirc.decode("", nil, 1)
|
|
43
|
+
end
|
|
44
|
+
assert_equal "Arguments width and height are required if binary string is passed", e.message
|
|
22
45
|
end
|
|
23
46
|
end
|
|
24
47
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: quirc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jacob Middag
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0.
|
|
61
|
+
version: '0.71'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0.
|
|
68
|
+
version: '0.71'
|
|
69
69
|
description: Ruby bindings for C library quirc that extracts and decode QR images
|
|
70
70
|
email: jacob@gaddim.nl
|
|
71
71
|
executables: []
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- test/fixtures/hello-120-utf8-l.png
|
|
92
92
|
- test/fixtures/hello-120-utf8-m.png
|
|
93
93
|
- test/fixtures/hello-120-utf8-q.png
|
|
94
|
+
- test/fixtures/hello.gz
|
|
94
95
|
- test/helper.rb
|
|
95
96
|
- test/test_decode.rb
|
|
96
97
|
homepage: https://github.com/middagj/quirc-ruby
|
|
@@ -105,15 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
105
106
|
requirements:
|
|
106
107
|
- - ">="
|
|
107
108
|
- !ruby/object:Gem::Version
|
|
108
|
-
version: '2.
|
|
109
|
+
version: '2.3'
|
|
109
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
requirements:
|
|
111
112
|
- - ">="
|
|
112
113
|
- !ruby/object:Gem::Version
|
|
113
114
|
version: '0'
|
|
114
115
|
requirements: []
|
|
115
|
-
|
|
116
|
-
rubygems_version: 2.7.6
|
|
116
|
+
rubygems_version: 3.0.3
|
|
117
117
|
signing_key:
|
|
118
118
|
specification_version: 4
|
|
119
119
|
summary: QR decoder based on quirc
|
|
@@ -122,5 +122,6 @@ test_files:
|
|
|
122
122
|
- test/fixtures/hello-120-utf8-l.png
|
|
123
123
|
- test/fixtures/hello-120-utf8-m.png
|
|
124
124
|
- test/fixtures/hello-120-utf8-q.png
|
|
125
|
+
- test/fixtures/hello.gz
|
|
125
126
|
- test/helper.rb
|
|
126
127
|
- test/test_decode.rb
|