qrencoder 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +33 -1
- data/lib/qrencoder.rb +2 -1
- data/lib/qrencoder/qrcode.rb +12 -13
- data/lib/qrencoder/version.rb +1 -1
- data/spec/integration_spec.rb +26 -13
- data/spec/qrcode_spec.rb +8 -3
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
== 1.3.4 / 2011-03-08
|
2
|
+
|
3
|
+
* 1 Minor enhancement
|
4
|
+
* Add pixels_per_module option for enlarging the PNG image by the
|
5
|
+
provided factor.
|
6
|
+
|
7
|
+
== 1.3.3 / 2011-03-08
|
8
|
+
|
9
|
+
* Fix bug with C extension location
|
10
|
+
|
11
|
+
== 1.3.2 / 2011-03-08
|
12
|
+
|
13
|
+
* Bugfix release. Gem erroneously included pre-compiled file.
|
14
|
+
|
15
|
+
== 1.3.1 / 2011-03-08
|
16
|
+
|
17
|
+
* Bugfix release
|
18
|
+
|
19
|
+
== 1.3.0 / 2011-03-08
|
20
|
+
|
21
|
+
* 1 Minor enhancement
|
22
|
+
* Use more maintain ChunkyPNG library instead of PNG
|
23
|
+
|
24
|
+
== 1.2.0 / 2011-02-23
|
25
|
+
|
26
|
+
* Major API change
|
27
|
+
* Everything is now wrapped in the QREncoder module
|
28
|
+
* QRCode.encode_string and QRCode.encode_string_ex are now handled
|
29
|
+
through a more conventional object initializer. See QRCode#initialize
|
30
|
+
for documentation.
|
31
|
+
* QREncoder includes a convenience method for creating QRCode objects.
|
32
|
+
See QREncoder.encode for details.
|
33
|
+
|
1
34
|
== 1.0.1 / 2008-03-11
|
2
35
|
|
3
36
|
* 1 Minor enhancement
|
@@ -7,4 +40,3 @@
|
|
7
40
|
|
8
41
|
* Initial release
|
9
42
|
* Wooo!
|
10
|
-
|
data/lib/qrencoder.rb
CHANGED
@@ -33,7 +33,7 @@ module QREncoder
|
|
33
33
|
# options. The options are as follows:
|
34
34
|
#
|
35
35
|
# [:version] An integer representing the minimum QRCode version (default: +1+)
|
36
|
-
# [:correction] The amount of error correction to apply. One of +:low+, +:medium+, +:high+. (default: +:low+)
|
36
|
+
# [:correction] The amount of error correction to apply. One of +:low+, +:medium+, +:quarter+, +:high+. (default: +:low+)
|
37
37
|
# [:mode] The encoding mode to use. Must be one of +:numeric+, +:alphanumeric+, +:ascii+, +:kanji+. (default: +:ascii+)
|
38
38
|
# [:case_sensitive] Set to +false+ if case does not matter. (default: +true+)
|
39
39
|
#
|
@@ -52,6 +52,7 @@ module QREncoder
|
|
52
52
|
{
|
53
53
|
:low => QR_ECLEVEL_L,
|
54
54
|
:medium => QR_ECLEVEL_M,
|
55
|
+
:quarter => QR_ECLEVEL_Q,
|
55
56
|
:high => QR_ECLEVEL_H
|
56
57
|
}
|
57
58
|
end
|
data/lib/qrencoder/qrcode.rb
CHANGED
@@ -13,13 +13,13 @@ module QREncoder
|
|
13
13
|
|
14
14
|
##
|
15
15
|
# Returns an instance of PNG, which can be saved to a file with PNG#save or
|
16
|
-
# converted to a blob for inline file transfer with PNG#to_blob.
|
17
|
-
# information, see http://seattlerb.rubyforge.org/png/
|
16
|
+
# converted to a blob for inline file transfer with PNG#to_blob.
|
18
17
|
#
|
19
18
|
# Options:
|
20
19
|
#
|
21
20
|
# [:margin] A pixel value for the margin around each side of the code. This should be 4 or greater. (default: +4+)
|
22
21
|
# [:transparent] Background transparency. Can be true or false. (default: +false+)
|
22
|
+
# [:pixels_per_module] Adjusts the entire PNG image by the given factor, integer. (default: +1+)
|
23
23
|
#
|
24
24
|
def png(options={})
|
25
25
|
canvas(options)
|
@@ -31,24 +31,23 @@ module QREncoder
|
|
31
31
|
# Takes an optional hash of options. See QRCode#png for details.
|
32
32
|
def canvas(options={})
|
33
33
|
@margin = options[:margin] || 4
|
34
|
+
ppm = options[:pixels_per_module] || 1
|
34
35
|
background = options[:transparent] ? ChunkyPNG::Color::TRANSPARENT : ChunkyPNG::Color::WHITE
|
35
|
-
png_width = width + (2 * @margin)
|
36
|
+
png_width = (width + (2 * @margin)) * ppm
|
36
37
|
|
37
38
|
canvas = ChunkyPNG::Image.new(png_width, png_width, background)
|
38
39
|
|
39
|
-
points.each do |
|
40
|
-
|
41
|
-
|
40
|
+
points.each do |point|
|
41
|
+
ppm.times do |x_offset|
|
42
|
+
x = (point[0] + @margin) * ppm + x_offset
|
43
|
+
ppm.times do |y_offset|
|
44
|
+
y = (point[1] + @margin) * ppm + y_offset
|
45
|
+
canvas[x,y] = ChunkyPNG::Color::BLACK
|
46
|
+
end
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
canvas
|
45
51
|
end
|
46
|
-
|
47
|
-
private
|
48
|
-
def png_coordinates_for_point(point)
|
49
|
-
x = point[0] + @margin
|
50
|
-
y = point[1] + @margin
|
51
|
-
[x,y]
|
52
|
-
end
|
53
52
|
end
|
54
53
|
end
|
data/lib/qrencoder/version.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -2,23 +2,36 @@ require 'spec_helper'
|
|
2
2
|
require 'zxing'
|
3
3
|
|
4
4
|
describe QREncoder do
|
5
|
-
context "
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it "creates decodable QRCode png files" do
|
13
|
-
QREncoder.encode(message).save_png(path)
|
14
|
-
ZXing.decode(path).should == message
|
15
|
-
end
|
5
|
+
context "integration" do
|
6
|
+
let(:path) { File.expand_path("../../tmp/integration.png", __FILE__) }
|
7
|
+
let(:options) { Hash.new }
|
8
|
+
let(:png) { QREncoder.encode(message).png(options) }
|
9
|
+
before do
|
10
|
+
File.unlink(path) if File.file?(path)
|
11
|
+
png.save(path)
|
16
12
|
end
|
17
|
-
|
13
|
+
|
14
|
+
subject { ZXing.decode(path) }
|
15
|
+
|
16
|
+
context "with a sentence" do
|
18
17
|
let(:message) {"Oh my! I'm amazed by technology."}
|
18
|
+
it { should == message }
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
context "with ascii characters" do
|
21
22
|
let(:message) {"&*@ad!jlfj-=+"}
|
23
|
+
it { should == message }
|
24
|
+
end
|
25
|
+
|
26
|
+
context "with a custom pixel per module size" do
|
27
|
+
let(:message) { "bigger" }
|
28
|
+
let(:options) do
|
29
|
+
{ :pixels_per_module => 4, :version => 1 }
|
30
|
+
end
|
31
|
+
it { should == message }
|
32
|
+
it "produces a larger png width and height" do
|
33
|
+
png.width.should == 29 * 4
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
data/spec/qrcode_spec.rb
CHANGED
@@ -22,12 +22,12 @@ describe QREncoder::QRCode do
|
|
22
22
|
|
23
23
|
describe "#dup" do
|
24
24
|
subject { QREncoder.encode("something").dup }
|
25
|
-
its(:width) { should == 21 }
|
25
|
+
its(:width) { should == 21 }
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#width" do
|
29
29
|
subject { QREncoder.encode("something").width }
|
30
|
-
it { should == 21 }
|
30
|
+
it { should == 21 }
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#version" do
|
@@ -158,11 +158,16 @@ describe QREncoder::QRCode do
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
context "with margin
|
161
|
+
context "with margin of 8" do
|
162
162
|
subject { qrcode.canvas(:margin => 8) }
|
163
163
|
its(:width) { should == qrcode.width + (8 * 2) }
|
164
164
|
end
|
165
165
|
|
166
|
+
context "with pixels-per-module of 2" do
|
167
|
+
subject { qrcode.canvas(:pixels_per_module => 2) }
|
168
|
+
its(:width) { should == (qrcode.width + 8) * 2 }
|
169
|
+
end
|
170
|
+
|
166
171
|
context "with transparent set to true" do
|
167
172
|
subject { qrcode.canvas(:transparent => true) }
|
168
173
|
specify "background should be transparent" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: qrencoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.3.
|
5
|
+
version: 1.3.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jacob Harris
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - ~>
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 0.2.1
|
60
60
|
type: :development
|
61
61
|
version_requirements: *id004
|
62
62
|
- !ruby/object:Gem::Dependency
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
requirements:
|
68
68
|
- - ~>
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: 1.0
|
70
|
+
version: 1.1.0
|
71
71
|
type: :runtime
|
72
72
|
version_requirements: *id005
|
73
73
|
description: |-
|
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
requirements: []
|
120
120
|
|
121
121
|
rubyforge_project:
|
122
|
-
rubygems_version: 1.6.
|
122
|
+
rubygems_version: 1.6.2
|
123
123
|
signing_key:
|
124
124
|
specification_version: 3
|
125
125
|
summary: Wrapper around the C qrencode library for creating QR Codes
|