rqrcode_png 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,8 @@ png = qr.to_img # returns an instance of ChunkyPNG
16
16
  png.resize(90, 90).save("really_cool_qr_image.png")
17
17
  ```
18
18
 
19
+ *NOTE:* For now, the :size of the QR code has to be 5 or less. Working on this.
20
+
19
21
  ### Bundler
20
22
  ```ruby
21
23
  gem 'rqrcode_png'
@@ -34,7 +36,7 @@ end
34
36
 
35
37
  ```ruby
36
38
  # somewhere
37
- qr_code_img = RQRCode::QRCode.new('http://www.google.com/').to_img
39
+ qr_code_img = RQRCode::QRCode.new('http://www.google.com/', :size => 4, :level => :h ).to_img
38
40
  @product.update_attribute :qr_code, qr_code_img.to_string
39
41
  ```
40
42
 
@@ -1,10 +1,7 @@
1
1
  module RQRCodePNG
2
2
  class Image
3
- BORDER = 2
4
- IMG_SIZE = 33
5
- TOTAL_IMG_SIZE = IMG_SIZE + BORDER * 2
6
3
  BLACK = ::ChunkyPNG::Color::BLACK
7
- WHITE = ::ChunkyPNG::Color::WHITE
4
+ WHITE = ::ChunkyPNG::Color::WHITE
8
5
 
9
6
  def initialize(qr_code)
10
7
  @sequence = Sequence.new(qr_code)
@@ -17,7 +14,7 @@ module RQRCodePNG
17
14
  png = blank_img()
18
15
 
19
16
  @sequence.dark_squares_only do |x, y|
20
- png[y + BORDER, x + BORDER] = BLACK
17
+ png[y + @sequence.border_width(), x + @sequence.border_width()] = BLACK
21
18
  end
22
19
 
23
20
  return png
@@ -25,13 +22,22 @@ module RQRCodePNG
25
22
 
26
23
  private
27
24
 
25
+ #
26
+ # Returns the size of the image
27
+ #
28
+ def img_size()
29
+ @img_size ||= @sequence.img_size() +
30
+ @sequence.border_width() * 2
31
+ end
32
+
28
33
  #
29
34
  # Returns an appropriately sized, blank (white) image
30
35
  #
31
36
  def blank_img
32
- ::ChunkyPNG::Image.new( TOTAL_IMG_SIZE,
33
- TOTAL_IMG_SIZE,
37
+ ::ChunkyPNG::Image.new( img_size(),
38
+ img_size(),
34
39
  WHITE )
35
40
  end
41
+
36
42
  end
37
43
  end
@@ -20,5 +20,18 @@ module RQRCodePNG
20
20
 
21
21
  end
22
22
 
23
+ #
24
+ # returns the image size by looking at how long the first line of the code is
25
+ #
26
+ def img_size
27
+ @img_size ||= @qr_code.to_s.split("\n").first.size()
28
+ end
29
+
30
+ #
31
+ # Returns the border, 1/10 of the img size
32
+ def border_width()
33
+ @border ||= img_size() / 10
34
+ end
35
+
23
36
  end
24
37
  end
@@ -1,3 +1,3 @@
1
1
  module RqrcodePng
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode_png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
16
- requirement: &2156140160 !ruby/object:Gem::Requirement
16
+ requirement: &2152638900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156140160
24
+ version_requirements: *2152638900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rqrcode
27
- requirement: &2156139740 !ruby/object:Gem::Requirement
27
+ requirement: &2152638480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156139740
35
+ version_requirements: *2152638480
36
36
  description: Glues rQRCode together with chunky_png
37
37
  email:
38
38
  - dcarper@dreamagile.com