Permalink
Browse files

Temporary fix to size bug... sizes 5 and less now work correctly

  • Loading branch information...
1 parent 45ab5cd commit c317efefeb93b149819c44226990c1e3c6ed7d1b @DCarper committed Oct 14, 2011
Showing with 28 additions and 9 deletions.
  1. +1 −1 README.markdown
  2. +13 −7 lib/rqrcode_png/image.rb
  3. +13 −0 lib/rqrcode_png/sequence.rb
  4. +1 −1 lib/rqrcode_png/version.rb
View
2 README.markdown
@@ -16,7 +16,7 @@ png = qr.to_img # returns an instance of ChunkyPNG
png.resize(90, 90).save("really_cool_qr_image.png")
```
-*NOTE:* For now, the :size of the QR code has to be 4. This will soon be fixed.
+*NOTE:* For now, the :size of the QR code has to be 5 or less. Working on this.
### Bundler
```ruby
View
20 lib/rqrcode_png/image.rb
@@ -1,10 +1,7 @@
module RQRCodePNG
class Image
- BORDER = 2
- IMG_SIZE = 33
- TOTAL_IMG_SIZE = IMG_SIZE + BORDER * 2
BLACK = ::ChunkyPNG::Color::BLACK
- WHITE = ::ChunkyPNG::Color::WHITE
+ WHITE = ::ChunkyPNG::Color::WHITE
def initialize(qr_code)
@sequence = Sequence.new(qr_code)
@@ -17,7 +14,7 @@ def render
png = blank_img()
@sequence.dark_squares_only do |x, y|
- png[y + BORDER, x + BORDER] = BLACK
+ png[y + @sequence.border_width(), x + @sequence.border_width()] = BLACK
end
return png
@@ -26,12 +23,21 @@ def render
private
#
+ # Returns the size of the image
+ #
+ def img_size()
+ @img_size ||= @sequence.img_size() +
+ @sequence.border_width() * 2
+ end
+
+ #
# Returns an appropriately sized, blank (white) image
#
def blank_img
- ::ChunkyPNG::Image.new( TOTAL_IMG_SIZE,
- TOTAL_IMG_SIZE,
+ ::ChunkyPNG::Image.new( img_size(),
+ img_size(),
WHITE )
end
+
end
end
View
13 lib/rqrcode_png/sequence.rb
@@ -20,5 +20,18 @@ def dark_squares_only(&block)
end
+ #
+ # returns the image size by looking at how long the first line of the code is
+ #
+ def img_size
+ @img_size ||= @qr_code.to_s.split("\n").first.size()
+ end
+
+ #
+ # Returns the border, 1/10 of the img size
+ def border_width()
+ @border ||= img_size() / 10
+ end
+
end
end
View
2 lib/rqrcode_png/version.rb
@@ -1,3 +1,3 @@
module RqrcodePng
- VERSION = "0.1.0"
+ VERSION = "0.1.1"
end

0 comments on commit c317efe

Please sign in to comment.