custom_rqrcode 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/lib/custom_rqrcode.rb +6 -39
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f42fb6ae55847d291deb52c0d21363724dceb4d4
|
4
|
+
data.tar.gz: 6a788af594a1fb7cc04c91272be9652166f02961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fdc7be3d1065f282f551b0940ee869847030cc11e52860e69634de2d2c2bf3e4f5642d649390d34265c2929b4f6e23b386a1b7005946f3a82e1c95faaba35c6
|
7
|
+
data.tar.gz: 79f7d303b3ae1b5a5c6c24b7eb3432a7ca5d43ce78017f559be56d81cae19e856fc08d73d885abaa799a9bf187ed34576cf485ec2f3a755bb60726911994b0cf
|
data/README.md
CHANGED
@@ -19,9 +19,7 @@ You will also want to add the **mini_magick** gem to your application's `Gemfile
|
|
19
19
|
## How to use
|
20
20
|
|
21
21
|
In your controller actions, you could return a QR code that links to the current page like this:
|
22
|
-
|
23
22
|
```ruby
|
24
|
-
First usage:
|
25
23
|
bg_image = Rails.root.join("app").to_s + ActionController::Base.helpers.asset_path("images/bg_image.png")
|
26
24
|
respond_to do |format|
|
27
25
|
format.html
|
@@ -31,7 +29,10 @@ respond_to do |format|
|
|
31
29
|
format.jpeg { render :qrcode => request.url }
|
32
30
|
end
|
33
31
|
|
34
|
-
|
32
|
+
```
|
33
|
+
|
34
|
+
In your controller actions, you could generate multiple QR codes on the background
|
35
|
+
```ruby
|
35
36
|
bg_image = Rails.root.join("app").to_s + ActionController::Base.helpers.asset_path("images/bg_image.png")
|
36
37
|
cqrcode = RQRCode::CQRCode.new
|
37
38
|
options = {
|
@@ -39,6 +40,8 @@ options = {
|
|
39
40
|
:bg => bg_image
|
40
41
|
}
|
41
42
|
cqrcode.generateQRcode(options, :png)
|
43
|
+
cqrcode.generateQRcode(options, :jpeg)
|
44
|
+
cqrcode.generateQRcode(options, :gif)
|
42
45
|
|
43
46
|
```
|
44
47
|
|
data/lib/custom_rqrcode.rb
CHANGED
@@ -15,42 +15,8 @@ module RQRCode
|
|
15
15
|
format = self.request.format.symbol
|
16
16
|
cqrcode = RQRCode::CQRCode.new
|
17
17
|
options[:info] = string
|
18
|
-
cqrcode.generateQRcode(options, format)
|
19
|
-
=begin
|
20
|
-
size = options[:size] || RQRCode.minimum_qr_size_from_string(string)
|
21
|
-
level = options[:level] || :h
|
18
|
+
data = cqrcode.generateQRcode(options, format)
|
22
19
|
|
23
|
-
bg = options[:bg] || false
|
24
|
-
bsize = options[:bsize] || false
|
25
|
-
geometry = options[:geometry] || "+00+00"
|
26
|
-
gravity = options[:gravity] || "north"
|
27
|
-
fsize = options[:fsize] || false
|
28
|
-
fsave = options[:fsave] || false
|
29
|
-
|
30
|
-
qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
|
31
|
-
svg = RQRCode::Renderers::SVG::render(qrcode, options)
|
32
|
-
|
33
|
-
data = \
|
34
|
-
if format && format == :svg
|
35
|
-
svg
|
36
|
-
else
|
37
|
-
image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
|
38
|
-
image.format format
|
39
|
-
|
40
|
-
if bg
|
41
|
-
bg_image = MiniMagick::Image.open bg
|
42
|
-
bg_image.resize bsize if bsize
|
43
|
-
image = bg_image.composite(image) do |c|
|
44
|
-
c.gravity gravity
|
45
|
-
c.geometry geometry
|
46
|
-
end
|
47
|
-
end
|
48
|
-
image.resize fsize if fsize
|
49
|
-
image.write fsave if fsave
|
50
|
-
|
51
|
-
image.to_blob
|
52
|
-
end
|
53
|
-
=end
|
54
20
|
self.response_body = render_to_string(:text => data, :template => nil)
|
55
21
|
end
|
56
22
|
|
@@ -83,7 +49,7 @@ module RQRCode
|
|
83
49
|
|
84
50
|
data = \
|
85
51
|
if format && format == :svg
|
86
|
-
|
52
|
+
svg
|
87
53
|
else
|
88
54
|
image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
|
89
55
|
image.format format
|
@@ -96,11 +62,12 @@ module RQRCode
|
|
96
62
|
c.geometry geometry
|
97
63
|
end
|
98
64
|
end
|
99
|
-
|
100
|
-
|
65
|
+
image.resize fsize if fsize
|
66
|
+
image.write fsave if fsave
|
101
67
|
|
102
|
-
|
68
|
+
image.to_blob
|
103
69
|
end
|
70
|
+
return data
|
104
71
|
end
|
105
72
|
end
|
106
73
|
end
|