pngqr 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README +8 -1
- data/lib/pngqr.rb +23 -5
- data/pngqr.gemspec +3 -4
- metadata +4 -16
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -16,12 +16,17 @@ Example:
|
|
16
16
|
Pngqr.encode 'https://github.com/andys', :file => 'output.png'
|
17
17
|
|
18
18
|
The parameters for encode() are the same as the rqrcode gem's new(), except:
|
19
|
+
|
19
20
|
1. we add :file if you want to output to a file instead of returning the PNG as
|
20
21
|
a blob, and
|
22
|
+
|
21
23
|
2. you can :scale with an integer parameter and it will scale up the output
|
22
24
|
image by that many times.
|
23
|
-
See: http://whomwah.github.com/rqrcode/
|
24
25
|
|
26
|
+
3. if you don't supply a :size, we auto-size by testing each size until we
|
27
|
+
find the one that worked. It seems quick enough.
|
28
|
+
|
29
|
+
4. :border=>n lets you add an n pixel white border to the PNG
|
25
30
|
|
26
31
|
|
27
32
|
Dependencies
|
@@ -29,6 +34,8 @@ Dependencies
|
|
29
34
|
|
30
35
|
Gems: rqrcode and chunky_png (both pure ruby gems)
|
31
36
|
|
37
|
+
See: http://whomwah.github.com/rqrcode/
|
38
|
+
|
32
39
|
|
33
40
|
|
34
41
|
|
data/lib/pngqr.rb
CHANGED
@@ -6,20 +6,38 @@ class Pngqr
|
|
6
6
|
class << self
|
7
7
|
|
8
8
|
def encode(*opts)
|
9
|
+
opthash = {}
|
9
10
|
if Hash===opts.last
|
10
|
-
|
11
|
-
@
|
11
|
+
opthash = opts.pop
|
12
|
+
@filename = opthash.delete(:file)
|
13
|
+
@scale = opthash.delete(:scale)
|
14
|
+
@border = opthash.delete(:border)
|
12
15
|
end
|
13
16
|
@scale ||= 1
|
17
|
+
@border ||= 0
|
14
18
|
|
15
|
-
qr =
|
19
|
+
qr = nil
|
20
|
+
if(opthash[:size]) # user supplied size
|
21
|
+
qr = RQRCode::QRCode.new(*opts, opthash)
|
22
|
+
else
|
23
|
+
# autosize algorithm: start at size=1 and increment until it worked
|
24
|
+
opthash[:size] = 1
|
25
|
+
while qr.nil?
|
26
|
+
qr = begin
|
27
|
+
RQRCode::QRCode.new(*opts, opthash)
|
28
|
+
rescue RQRCode::QRCodeRunTimeError => e
|
29
|
+
opthash[:size] += 1
|
30
|
+
raise unless e.to_s =~ /overflow/ && opthash[:size] <= 40
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
16
34
|
len = qr.module_count
|
17
|
-
png = ChunkyPNG::Image.new(len*@scale, len*@scale, ChunkyPNG::Color::WHITE)
|
35
|
+
png = ChunkyPNG::Image.new(len*@scale + 2*@border, len*@scale + 2*@border, ChunkyPNG::Color::WHITE)
|
18
36
|
|
19
37
|
for_each_pixel(len) do |x,y|
|
20
38
|
if qr.modules[y][x]
|
21
39
|
for_each_scale(x, y, @scale) do |scaled_x, scaled_y|
|
22
|
-
png[scaled_x, scaled_y] = ChunkyPNG::Color::BLACK
|
40
|
+
png[scaled_x + @border, scaled_y + @border] = ChunkyPNG::Color::BLACK
|
23
41
|
end
|
24
42
|
end
|
25
43
|
end
|
data/pngqr.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{pngqr}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Andrew Snow"]
|
9
|
-
s.date = %q{2011-03-
|
9
|
+
s.date = %q{2011-03-17}
|
10
10
|
s.description = %q{Ruby Gem to generate PNG files with QR codes in them}
|
11
11
|
s.email = %q{andrew@modulus.org}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README", "lib/pngqr.rb"]
|
@@ -15,11 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pngqr", "--main", "README"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{pngqr}
|
18
|
-
s.rubygems_version = %q{1.
|
18
|
+
s.rubygems_version = %q{1.6.2}
|
19
19
|
s.summary = %q{Ruby Gem to generate PNG files with QR codes in them}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
22
|
s.specification_version = 3
|
24
23
|
|
25
24
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
metadata
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pngqr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
version: "0.3"
|
4
|
+
prerelease:
|
5
|
+
version: "0.4"
|
9
6
|
platform: ruby
|
10
7
|
authors:
|
11
8
|
- Andrew Snow
|
@@ -13,7 +10,7 @@ autorequire:
|
|
13
10
|
bindir: bin
|
14
11
|
cert_chain: []
|
15
12
|
|
16
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-17 00:00:00 +11:00
|
17
14
|
default_executable:
|
18
15
|
dependencies:
|
19
16
|
- !ruby/object:Gem::Dependency
|
@@ -24,8 +21,6 @@ dependencies:
|
|
24
21
|
requirements:
|
25
22
|
- - ">="
|
26
23
|
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
24
|
version: "0"
|
30
25
|
type: :runtime
|
31
26
|
version_requirements: *id001
|
@@ -37,8 +32,6 @@ dependencies:
|
|
37
32
|
requirements:
|
38
33
|
- - ">="
|
39
34
|
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 0
|
42
35
|
version: "0"
|
43
36
|
type: :runtime
|
44
37
|
version_requirements: *id002
|
@@ -78,22 +71,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
71
|
requirements:
|
79
72
|
- - ">="
|
80
73
|
- !ruby/object:Gem::Version
|
81
|
-
segments:
|
82
|
-
- 0
|
83
74
|
version: "0"
|
84
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
76
|
none: false
|
86
77
|
requirements:
|
87
78
|
- - ">="
|
88
79
|
- !ruby/object:Gem::Version
|
89
|
-
segments:
|
90
|
-
- 1
|
91
|
-
- 2
|
92
80
|
version: "1.2"
|
93
81
|
requirements: []
|
94
82
|
|
95
83
|
rubyforge_project: pngqr
|
96
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.6.2
|
97
85
|
signing_key:
|
98
86
|
specification_version: 3
|
99
87
|
summary: Ruby Gem to generate PNG files with QR codes in them
|