rqrcode_png 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,53 @@
1
1
  # rqrcode_png
2
+ **Problem:** You need to generate your own QR code images
3
+ **Solution:** rqrcode_png
2
4
 
3
5
  ## Overview
4
- rQRcode is a great library that generates the 2D sequence of a QR code, and chunky_png is a great pure ruby library for generating and manipulating images.
6
+ rqrcode_png extends [rqrcode](https://github.com/whomwah/rqrcode), adding one simple method to instances of QRCode, **\#to_img**. [ChunkyPNG](https://github.com/wvanbergen/chunky_png) is used to generate the image itself in pure Ruby. As few assumptions are made as possible regarding the image itself.
5
7
 
6
- rqrcode_png ties the two libraries together. rqrcode_png assumes as little as possible.
7
8
 
8
9
  ## Usage
9
- qrqcode_png extends RQRCode::QRCode with one simple method, #to_img.
10
-
11
- \#to_img returns an instance of ChunkyPNG. The image itself is 37x37 pixels which includes a 2 pixel border, which can easily be resized and saved.
12
10
 
13
11
  ```ruby
12
+ require 'rqrcode_png'
13
+
14
14
  qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
15
- png = qr.to_img
16
- png.resize(90, 90).save("really_cool_qr_image.png") # ChunkyPNG methods
15
+ png = qr.to_img # returns an instance of ChunkyPNG
16
+ png.resize(90, 90).save("really_cool_qr_image.png")
17
+ ```
18
+
19
+ ### Bundler
20
+ ```ruby
21
+ gem 'rqrcode_png'
22
+ ```
23
+
24
+ ### Rails
25
+
26
+ #### With [DragonFly](https://github.com/markevans/dragonfly)
27
+
28
+ ```ruby
29
+ # app/models/product.rb
30
+ class Product < ActiveRecord::Base
31
+ image_accessor :qr_code
32
+ end
33
+ ```
34
+
35
+ ```ruby
36
+ # somewhere
37
+ qr_code_img = RQRCode::QRCode.new('http://www.google.com/').to_img
38
+ @product.update_attribute :qr_code, qr_code_img.to_string
39
+ ```
40
+
41
+ ```ruby
42
+ # app/controllers/products.rb
43
+ def show
44
+ @product = Product.find(params[:id])
45
+ end
46
+ ```
47
+
48
+ ```ruby
49
+ # app/views/products/show.html.erb
50
+ <%= image_tag @product.qr_code.url %>
17
51
  ```
18
52
 
19
53
  ## Contributing
@@ -22,6 +56,5 @@ png.resize(90, 90).save("really_cool_qr_image.png") # ChunkyPNG methods
22
56
  * Don't touch the .gemspec, I'll do that when I release a new version
23
57
 
24
58
  ## Copyright
25
-
26
59
  MIT Licence (http://www.opensource.org/licenses/mit-license.html)
27
60
 
@@ -1,8 +1,9 @@
1
- require "chunky_png"
1
+ require 'chunky_png'
2
2
  require 'rqrcode'
3
3
 
4
- require "rqrcode_png/version"
5
- require "rqrcode_png/image"
6
- require "rqrcode_png/qrcode_extensions"
4
+ require 'rqrcode_png/version'
5
+ require 'rqrcode_png/sequence'
6
+ require 'rqrcode_png/image'
7
+ require 'rqrcode_png/qrcode_extensions'
7
8
 
8
9
  RQRCode::QRCode.send :include, RQRCodePNG::QRCodeExtensions
@@ -6,10 +6,8 @@ module RQRCodePNG
6
6
  BLACK = ::ChunkyPNG::Color::BLACK
7
7
  WHITE = ::ChunkyPNG::Color::WHITE
8
8
 
9
- attr_accessor :qr_code
10
-
11
9
  def initialize(qr_code)
12
- self.qr_code = qr_code
10
+ @sequence = Sequence.new(qr_code)
13
11
  end
14
12
 
15
13
  #
@@ -18,7 +16,7 @@ module RQRCodePNG
18
16
  def render
19
17
  png = blank_img()
20
18
 
21
- qr_code().dark_squares_only do |x, y|
19
+ @sequence.dark_squares_only do |x, y|
22
20
  png[y + BORDER, x + BORDER] = BLACK
23
21
  end
24
22
 
@@ -1,25 +1,13 @@
1
1
  module RQRCodePNG
2
2
 
3
3
  module QRCodeExtensions
4
+
5
+ #
4
6
  # This method returns a 33x33 .png of the code
5
7
  #
6
8
  def to_img
7
9
  return Image.new(self).render()
8
10
  end
9
-
10
- #
11
- # This method yields the vertices of the dark squares
12
- #
13
- def dark_squares_only(&block)
14
- self.modules.each_index do |row|
15
- self.modules.each_index do |column|
16
- if self.dark?(row, column)
17
- yield row, column
18
- end
19
- end
20
- end
21
-
22
- end
23
11
 
24
12
  end
25
13
  end
@@ -0,0 +1,24 @@
1
+ module RQRCodePNG
2
+
3
+ class Sequence
4
+
5
+ def initialize(qr_code)
6
+ @qr_code = qr_code
7
+ end
8
+
9
+ #
10
+ # This method yields the vertices of the dark squares
11
+ #
12
+ def dark_squares_only(&block)
13
+ @qr_code.modules.each_index do |row|
14
+ @qr_code.modules.each_index do |column|
15
+ if @qr_code.dark?(row, column)
16
+ yield row, column
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module RqrcodePng
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
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.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-08 00:00:00.000000000Z
12
+ date: 2011-10-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
16
- requirement: &2157538300 !ruby/object:Gem::Requirement
16
+ requirement: &2156140160 !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: *2157538300
24
+ version_requirements: *2156140160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rqrcode
27
- requirement: &2157537880 !ruby/object:Gem::Requirement
27
+ requirement: &2156139740 !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: *2157537880
35
+ version_requirements: *2156139740
36
36
  description: Glues rQRCode together with chunky_png
37
37
  email:
38
38
  - dcarper@dreamagile.com
@@ -48,6 +48,7 @@ files:
48
48
  - lib/rqrcode_png.rb
49
49
  - lib/rqrcode_png/image.rb
50
50
  - lib/rqrcode_png/qrcode_extensions.rb
51
+ - lib/rqrcode_png/sequence.rb
51
52
  - lib/rqrcode_png/version.rb
52
53
  - rqrcode_png.gemspec
53
54
  homepage: ''