rqrcode 0.6.0 → 0.7.0
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/.travis.yml +3 -3
- data/CHANGELOG +4 -0
- data/Gemfile +1 -1
- data/README.md +86 -83
- data/TODO.md +1 -0
- data/lib/rqrcode/export/png.rb +1 -1
- data/lib/rqrcode/export/svg.rb +12 -8
- data/lib/rqrcode/qrcode/qr_code.rb +24 -19
- data/lib/rqrcode/qrcode/qr_util.rb +4 -0
- data/lib/rqrcode/version.rb +1 -1
- data/test/test_rqrcode.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1275547d28967654aa0f1ba1a450c5daa31c582a
|
4
|
+
data.tar.gz: c6ae31e4cdea2370f20a147cbc6f41f6d7d2fdc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 916f34ba9af9afffbfd8ba55116fc130b32a3ffb89db779da2af89df0c167fe49138fd625a33f1f48d648729ae488742921b2dfa10f6349743ff9ac7d865f7e3
|
7
|
+
data.tar.gz: 6ebffce16883fcf0951c6bd601915e1335a709b216cfa2255e1c56b45e496e42b301724f117d81134f403a93960d743b7eb3676239584562622eec216a33226e
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,10 @@
|
|
4
4
|
|
5
5
|
## Short changelog
|
6
6
|
|
7
|
+
*0.7.0* (Aug 15, 2015)
|
8
|
+
|
9
|
+
- Added shape_rendering option for as_svg
|
10
|
+
|
7
11
|
*0.6.0* (Jun 2, 2015)
|
8
12
|
|
9
13
|
- Improved png rendering. Previous png rendering could result in hard to scan qrcodes.
|
@@ -25,128 +29,127 @@ Let's clear up some rQRCode stuff.
|
|
25
29
|
* The interface is simple and assumes you just want to encode a string into a QR code
|
26
30
|
* QR code is trademarked by Denso Wave inc
|
27
31
|
|
28
|
-
## Resources
|
29
|
-
|
30
|
-
* wikipedia:: http://en.wikipedia.org/wiki/QR_Code
|
31
|
-
* Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
|
32
|
-
* kaywa:: http://qrcode.kaywa.com
|
33
|
-
|
34
32
|
## Installing
|
35
33
|
|
36
34
|
You may get the latest stable version from Rubygems.
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
```ruby
|
37
|
+
gem install rqrcode
|
38
|
+
```
|
41
39
|
|
42
|
-
|
40
|
+
## Using rQRCode
|
43
41
|
|
44
|
-
|
42
|
+
```ruby
|
43
|
+
require 'rqrcode'
|
45
44
|
|
46
|
-
|
45
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
46
|
+
image = qrcode.as_png
|
47
|
+
svg = qrcode.as_svg
|
48
|
+
html = qrcode.as_html
|
49
|
+
string = qrcode.to_s
|
50
|
+
```
|
47
51
|
|
48
|
-
|
52
|
+
## Image Rendering
|
53
|
+
### SVG
|
49
54
|
|
50
|
-
|
55
|
+
The SVG renderer will produce a stand-alone SVG as a `String`
|
51
56
|
|
52
|
-
|
57
|
+
```ruby
|
58
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
59
|
+
# With default options specified explicitly
|
60
|
+
svg = qrcode.as_svg(offset: 0, color: '000',
|
61
|
+
shape_rendering: 'crispEdges',
|
62
|
+
module_size: 11)
|
63
|
+
```
|
53
64
|
|
54
|
-
|
55
|
-
require 'rqrcode'
|
65
|
+
### PNG
|
56
66
|
|
57
|
-
|
67
|
+
The library can produce a PNG. Result will be a `ChunkyPNG::Image` instance.
|
58
68
|
|
59
69
|
```ruby
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
qrcode = RQRCode::QRCode.new("http://github.com/")
|
71
|
+
# With default options specified explicitly
|
72
|
+
png = qrcode.as_png(
|
73
|
+
resize_gte_to: false,
|
74
|
+
resize_exactly_to: false,
|
75
|
+
fill: 'white',
|
76
|
+
color: 'black',
|
77
|
+
size: 120,
|
78
|
+
border_modules: 4,
|
79
|
+
file: false,
|
80
|
+
module_px_size: 6,
|
81
|
+
output_file: nil # path to write
|
82
|
+
)
|
68
83
|
```
|
69
84
|
|
70
|
-
##
|
71
|
-
###
|
85
|
+
## HTML Rendering
|
86
|
+
### In your controller
|
72
87
|
```ruby
|
73
|
-
@qr = RQRCode::QRCode.new( '
|
88
|
+
@qr = RQRCode::QRCode.new( 'https://github.com/whomwah/rqrcode', :size => 4, :level => :h )
|
74
89
|
```
|
75
|
-
|
76
|
-
|
77
|
-
|
90
|
+
|
91
|
+
### In your view
|
92
|
+
```html
|
93
|
+
<%= raw @qr.as_html %>
|
94
|
+
```
|
95
|
+
|
96
|
+
### CSS
|
97
|
+
```css
|
78
98
|
table {
|
79
99
|
border-width: 0;
|
80
100
|
border-style: none;
|
81
101
|
border-color: #0000ff;
|
82
102
|
border-collapse: collapse;
|
83
103
|
}
|
104
|
+
|
84
105
|
td {
|
85
|
-
border-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
margin: 0;
|
91
|
-
width: 10px;
|
92
|
-
height: 10px;
|
106
|
+
border-left: solid 10px #000;
|
107
|
+
padding: 0;
|
108
|
+
margin: 0;
|
109
|
+
width: 0px;
|
110
|
+
height: 10px;
|
93
111
|
}
|
94
|
-
td.black { background-color: #000; }
|
95
|
-
td.white { background-color: #fff; }
|
96
|
-
</style>
|
97
112
|
|
98
|
-
|
113
|
+
td.black { border-color: #000; }
|
114
|
+
td.white { border-color: #fff; }
|
99
115
|
```
|
116
|
+
|
117
|
+
## On the console
|
100
118
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
<table>
|
105
|
-
<% @qr.modules.each_index do |x| %>
|
106
|
-
<tr>
|
107
|
-
<% @qr.modules.each_index do |y| %>
|
108
|
-
<% if @qr.dark?(x,y) %>
|
109
|
-
<td class="black"/>
|
110
|
-
<% else %>
|
111
|
-
<td class="white"/>
|
112
|
-
<% end %>
|
113
|
-
<% end %>
|
114
|
-
</tr>
|
115
|
-
<% end %>
|
116
|
-
</table>
|
119
|
+
```ruby
|
120
|
+
qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
121
|
+
puts qr.to_s
|
117
122
|
```
|
118
123
|
|
119
|
-
|
120
|
-
|
121
|
-
You can also require optional export features:
|
124
|
+
Output:
|
122
125
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
```
|
127
|
+
xxxxxxx x x x x x xx xxxxxxx
|
128
|
+
x x xxx xxxxxx xxx x x
|
129
|
+
x xxx x xxxxx x xx x xxx x
|
130
|
+
... etc
|
131
|
+
```
|
128
132
|
|
133
|
+
## Doing your own rendering
|
129
134
|
```ruby
|
130
|
-
|
131
|
-
|
135
|
+
qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
136
|
+
qr.modules.each do |row|
|
137
|
+
row.each do |col|
|
138
|
+
print col ? "X" : " "
|
139
|
+
end
|
140
|
+
print "\n"
|
141
|
+
end
|
132
142
|
```
|
133
143
|
|
134
|
-
|
135
|
-
|
136
|
-
### Export Options
|
144
|
+
## API Documentation
|
137
145
|
|
138
|
-
|
146
|
+
[http://www.rubydoc.info/gems/rqrcode](http://www.rubydoc.info/gems/rqrcode)
|
139
147
|
|
140
|
-
|
141
|
-
* fill - Background color, defaults to 'white'
|
142
|
-
* color - Foreground color, defaults to 'black'
|
143
|
-
|
144
|
-
SVG Export supports the parameter `module_size` to generate smaller or larger QR Codes
|
148
|
+
## Resources
|
145
149
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
```
|
150
|
+
* wikipedia:: http://en.wikipedia.org/wiki/QR_Code
|
151
|
+
* Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
|
152
|
+
* kaywa:: http://qrcode.kaywa.com
|
150
153
|
|
151
154
|
## Authors
|
152
155
|
|
data/TODO.md
CHANGED
data/lib/rqrcode/export/png.rb
CHANGED
@@ -11,7 +11,7 @@ module RQRCode
|
|
11
11
|
# There are two sizing algoritams.
|
12
12
|
#
|
13
13
|
# - Original that can result in blurry and hard to scan images
|
14
|
-
# - Google's Chart API inspired sizing that
|
14
|
+
# - Google's Chart API inspired sizing that resizes the module size to fit within the given image size.
|
15
15
|
#
|
16
16
|
# The Googleis one will be used when no options are given or when the new size option is used.
|
17
17
|
#
|
data/lib/rqrcode/export/svg.rb
CHANGED
@@ -3,24 +3,28 @@
|
|
3
3
|
module RQRCode
|
4
4
|
module Export
|
5
5
|
|
6
|
-
# Render the SVG from the Qrcode.
|
7
|
-
#
|
8
|
-
# Options:
|
9
|
-
# offset - Padding around the QR Code (e.g. 10)
|
10
|
-
# fill - Background color (e.g "ffffff" or :white)
|
11
|
-
# color - Foreground color for the code (e.g. "000000" or :black)
|
12
|
-
# module_size - The Pixel size of each module (e.g. 11)
|
13
6
|
module SVG
|
7
|
+
|
8
|
+
# Render the SVG from the Qrcode.
|
9
|
+
#
|
10
|
+
# Options:
|
11
|
+
# offset - Padding around the QR Code (e.g. 10)
|
12
|
+
# fill - Background color (e.g "ffffff" or :white)
|
13
|
+
# color - Foreground color for the code (e.g. "000000" or :black)
|
14
|
+
# module_size - The Pixel size of each module (e.g. 11)
|
15
|
+
# shape_rendering - Defaults to crispEdges
|
16
|
+
#
|
14
17
|
def as_svg(options={})
|
15
18
|
offset = options[:offset].to_i || 0
|
16
19
|
color = options[:color] || "000"
|
20
|
+
shape_rendering = options[:shape_rendering] || "crispEdges"
|
17
21
|
module_size = options[:module_size] || 11
|
18
22
|
|
19
23
|
# height and width dependent on offset and QR complexity
|
20
24
|
dimension = (self.module_count*module_size) + (2*offset)
|
21
25
|
|
22
26
|
xml_tag = %{<?xml version="1.0" standalone="yes"?>}
|
23
|
-
open_tag = %{<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="#{dimension}" height="#{dimension}">}
|
27
|
+
open_tag = %{<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="#{dimension}" height="#{dimension}" shape-rendering="#{shape_rendering}">}
|
24
28
|
close_tag = "</svg>"
|
25
29
|
|
26
30
|
result = []
|
@@ -121,6 +121,10 @@ module RQRCode #:nodoc:
|
|
121
121
|
|
122
122
|
max_size_array = QRMAXDIGITS[level][mode]
|
123
123
|
size = options[:size] || smallest_size_for(string, max_size_array)
|
124
|
+
|
125
|
+
if size > QRUtil.max_size
|
126
|
+
raise QRCodeArgumentError, "Given size greater than maximum possible size of #{QRUtil.max_size}"
|
127
|
+
end
|
124
128
|
|
125
129
|
@error_correct_level = QRERRORCORRECTLEVEL[level]
|
126
130
|
@version = size
|
@@ -160,31 +164,32 @@ module RQRCode #:nodoc:
|
|
160
164
|
# x x xxx xxxxxx xxx x x
|
161
165
|
# x xxx x xxxxx x xx x xxx x
|
162
166
|
#
|
163
|
-
# instance._to_s( :
|
167
|
+
# instance._to_s( :dark => 'E', :light => 'Q') =>
|
164
168
|
# EEEEEEEQEQQEQEQQQEQEQQEEQQEEEEEEE
|
165
169
|
# EQQQQQEQQEEEQQEEEEEEQEEEQQEQQQQQE
|
166
170
|
# EQEEEQEQQEEEEEQEQQQQQQQEEQEQEEEQE
|
167
171
|
#
|
168
|
-
|
169
172
|
def to_s( *args )
|
170
173
|
options = args.extract_options!
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
else
|
182
|
-
tmp << col
|
183
|
-
end
|
174
|
+
dark = options[:dark] || options[:true] || 'x'
|
175
|
+
light = options[:light] || options[:false] || ' '
|
176
|
+
quiet_zone_size = options[:quiet_zone_size] || 0
|
177
|
+
|
178
|
+
rows = []
|
179
|
+
|
180
|
+
@modules.each do |row|
|
181
|
+
cols = light * quiet_zone_size
|
182
|
+
row.each do |col|
|
183
|
+
cols += (col ? dark : light)
|
184
184
|
end
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
rows << cols
|
186
|
+
end
|
187
|
+
|
188
|
+
quiet_zone_size.times do
|
189
|
+
rows.unshift(light * (rows.first.length / light.size))
|
190
|
+
rows << light * (rows.first.length / light.size)
|
191
|
+
end
|
192
|
+
rows.join("\n")
|
188
193
|
end
|
189
194
|
|
190
195
|
protected
|
@@ -392,7 +397,7 @@ module RQRCode #:nodoc:
|
|
392
397
|
buffer.end_of_message(max_data_bits)
|
393
398
|
|
394
399
|
if buffer.get_length_in_bits > max_data_bits
|
395
|
-
raise QRCodeRunTimeError, "code length overflow. (#{buffer.get_length_in_bits}>#{max_data_bits})"
|
400
|
+
raise QRCodeRunTimeError, "code length overflow. (#{buffer.get_length_in_bits}>#{max_data_bits}). (Try a larger size!)"
|
396
401
|
end
|
397
402
|
|
398
403
|
buffer.pad_until(max_data_bits)
|
@@ -73,6 +73,10 @@ module RQRCode #:nodoc:
|
|
73
73
|
QRMODE[:mode_kanji] => [8, 10, 12],
|
74
74
|
}
|
75
75
|
|
76
|
+
def QRUtil.max_size
|
77
|
+
PATTERN_POSITION_TABLE.count
|
78
|
+
end
|
79
|
+
|
76
80
|
def QRUtil.get_bch_format_info( data )
|
77
81
|
d = data << 10
|
78
82
|
while QRUtil.get_bch_digit(d) - QRUtil.get_bch_digit(G15) >= 0
|
data/lib/rqrcode/version.rb
CHANGED
data/test/test_rqrcode.rb
CHANGED
@@ -101,6 +101,12 @@ class QRCodeTest < Test::Unit::TestCase
|
|
101
101
|
assert RQRCode::QRCode.new("40952", :size => 1, :level => :h)
|
102
102
|
assert RQRCode::QRCode.new("40932", :size => 1, :level => :h)
|
103
103
|
end
|
104
|
+
|
105
|
+
def test_exceed_max_size
|
106
|
+
assert_raise RQRCode::QRCodeArgumentError do
|
107
|
+
RQRCode::QRCode.new( 'duncan', :size => 41 )
|
108
|
+
end
|
109
|
+
end
|
104
110
|
|
105
111
|
def test_levels
|
106
112
|
assert RQRCode::QRCode.new("duncan", :level => :l)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rqrcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Björn Blomqvist
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chunky_png
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: 1.3.6
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.4.8
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: A library to encode QR Codes
|