custom_rqrcode 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -0
  3. data/lib/custom_rqrcode.rb +60 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3df50cdf822f9454e26a23e4a24771725ec5eb7
4
- data.tar.gz: 41f621a0df051fa70ef6c7fb0d57950cc1196a49
3
+ metadata.gz: ea62843afa1136c33b482736004244e7f79de76e
4
+ data.tar.gz: fb159070123aecb6640b9799427da317bdc83c33
5
5
  SHA512:
6
- metadata.gz: 28ac53659429639d48a6dc7dcda7ae0a1391fa572a9c5c724846813210754b52a579a7766ef467a01868fe9ac50e1f2f258d3dcc2b7a6d4dace964c5d7e58280
7
- data.tar.gz: 4851970adc32577a6c8284096a2a5f6c6bd1480d8865aa2d043935623e7dfdaec72b702cc588a2f08b6c990428d4849fb1b3c0754cb6efa2326144814643ac61
6
+ metadata.gz: 5b17d23753bc4c532758f2143521e19933b122dc9ef90da9b526cd11e4dfbdc6fda052bacd3930ad85666266779cb2b5bc5530fbc250da64bef05b2b5ad28780
7
+ data.tar.gz: 450aa6e408409ce91e1a4214e4ea750a93f392d64eb6195631217977885a56ae17a5a86fe2475b70102eec1a8175ab4fd12d95bd7c6bb230784fa460b1ef36ed
data/README.md CHANGED
@@ -21,6 +21,7 @@ You will also want to add the **mini_magick** gem to your application's `Gemfile
21
21
  In your controller actions, you could return a QR code that links to the current page like this:
22
22
 
23
23
  ```ruby
24
+ First usage:
24
25
  bg_image = Rails.root.join("app").to_s + ActionController::Base.helpers.asset_path("images/bg_image.png")
25
26
  respond_to do |format|
26
27
  format.html
@@ -29,6 +30,16 @@ respond_to do |format|
29
30
  format.gif { render :qrcode => request.url }
30
31
  format.jpeg { render :qrcode => request.url }
31
32
  end
33
+
34
+ Second usage:
35
+ bg_image = Rails.root.join("app").to_s + ActionController::Base.helpers.asset_path("images/bg_image.png")
36
+ cqrcode = RQRCode::CQRCode.new
37
+ options = {
38
+ :info => "Hi there.",
39
+ :bg => bg_image
40
+ }
41
+ cqrcode.generateQRcode(options, :png)
42
+
32
43
  ```
33
44
 
34
45
  #### Options:
@@ -49,6 +60,7 @@ end
49
60
  * `:geometry` – Adjust the position specifically where QR code image will be located on the image (e.g. "+00+10", "-10+30")
50
61
  * `:fsize` – Resize final images (e.g. "400x300")
51
62
  * `:fsave` – Save final images (e.g. "/images/qrcode/1.png" or "/img/0.jpg")
63
+ * `:info` – A string to be encoded (only for second usage)
52
64
 
53
65
  ## About
54
66
 
@@ -12,7 +12,11 @@ module RQRCode
12
12
  extend SizeCalculator
13
13
 
14
14
  ActionController::Renderers.add :qrcode do |string, options|
15
- format = self.request.format.symbol
15
+ format = self.request.format.symbol
16
+ cqrcode = RQRCode::CQRCode.new
17
+ options[:info] = string
18
+ cqrcode.generateQRcode(options, format)
19
+ =begin
16
20
  size = options[:size] || RQRCode.minimum_qr_size_from_string(string)
17
21
  level = options[:level] || :h
18
22
 
@@ -22,13 +26,13 @@ module RQRCode
22
26
  gravity = options[:gravity] || "north"
23
27
  fsize = options[:fsize] || false
24
28
  fsave = options[:fsave] || false
25
-
29
+
26
30
  qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
27
31
  svg = RQRCode::Renderers::SVG::render(qrcode, options)
28
32
 
29
33
  data = \
30
34
  if format && format == :svg
31
- svg
35
+ svg
32
36
  else
33
37
  image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
34
38
  image.format format
@@ -41,12 +45,62 @@ module RQRCode
41
45
  c.geometry geometry
42
46
  end
43
47
  end
48
+ image.resize fsize if fsize
49
+ image.write fsave if fsave
50
+
51
+ image.to_blob
52
+ end
53
+ =end
54
+ self.response_body = render_to_string(:text => data, :template => nil)
55
+ end
56
+
57
+ class CQRCode
58
+ @@defaults = {
59
+ :info => "no data",
60
+ :bg => false,
61
+ :bsize => false,
62
+ :gravity => "north",
63
+ :geometry => "+00+00",
64
+ :fsize => false,
65
+ :fsave => false
66
+ }
67
+
68
+ def generateQRcode(options={}, format=:svg)
69
+ options = @@defaults.merge(options)
70
+ string = options[:info]
71
+ size = options[:size] || RQRCode.minimum_qr_size_from_string(string)
72
+ level = options[:level] || :h
73
+
74
+ bg = options[:bg]
75
+ bsize = options[:bsize]
76
+ geometry = options[:geometry]
77
+ gravity = options[:gravity]
78
+ fsize = options[:fsize]
79
+ fsave = options[:fsave]
80
+
81
+ qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
82
+ svg = RQRCode::Renderers::SVG::render(qrcode, options)
83
+
84
+ data = \
85
+ if format && format == :svg
86
+ svg
87
+ else
88
+ image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
89
+ image.format format
90
+
91
+ if bg
92
+ bg_image = MiniMagick::Image.open bg
93
+ bg_image.resize bsize if bsize
94
+ image = bg_image.composite(image) do |c|
95
+ c.gravity gravity
96
+ c.geometry geometry
97
+ end
98
+ end
44
99
  image.resize fsize if fsize
45
100
  image.write fsave if fsave
46
-
101
+
47
102
  image.to_blob
103
+ end
48
104
  end
49
-
50
- self.response_body = render_to_string(:text => data, :template => nil)
51
105
  end
52
106
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_rqrcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnson Chang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rqrcode