custom_rqrcode 0.0.2 → 0.0.3

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 +7 -5
  3. data/lib/custom_rqrcode.rb +7 -15
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef2f8329c3650f1476d38103fc63a82dce86e9aa
4
- data.tar.gz: c999d5bbef2592952ee487635f54b47ef8144a3d
3
+ metadata.gz: 91c0f8ed5ebefd7c835dcaf83421aa559014f846
4
+ data.tar.gz: 2596cb66a575f2c94e35af9de297a0194392a0ca
5
5
  SHA512:
6
- metadata.gz: 2582e340f28f2485162986d96a2b0138a24a2305c71a9832fa831583fb4d636d5064509757700ddd3f1ab1352e2d6d790e861c99c4062f565b8ecac8f633fb1e
7
- data.tar.gz: ed5aa61ed58d0cbf203b24b1638fd8b7a89b9659c145fc87096c9ac66d7a08078e82c18aefbb169a5d4ff13dfde3e9e7d9eb25db454200082c14088f3b896108
6
+ metadata.gz: 8ac82bc6f6804c945109c64b2a14c7cca7cd7d1cc9c7521f41b074036b85e8176b08d9f2697c33e69e75b828cfc5591f552fd10ea55ed23ed133a0ee30f150fd
7
+ data.tar.gz: 774e9a8559c4f06d1a29a094bf0427d016bb344a70191233fff3655d392afe5575841c1999cb4f6be61d1479bb7a21b62aafa6329439b71f7654c709620e3783
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Render and customize QR codes from Rails 3 applications
1
+ # Render and customize QR codes with a background image
2
2
 
3
- This gem extends rqrcode-rails published by samvincent, supporting the output in either SVG or PNG, JPEG, and GIF formats and
3
+ This gem extends rqrcode-rails published by samvincent, supporting the output in either SVG or PNG,
4
4
 
5
- providing new options to set background image combined with QR code image.
5
+ JPEG, and GIF formats and providing new options to set background image combined with QR code image.
6
6
 
7
7
 
8
8
  ## Installation
@@ -21,10 +21,11 @@ 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
+ bg_image = Rails.root.join("app").to_s + ActionController::Base.helpers.asset_path("images/bg_image.png")
24
25
  respond_to do |format|
25
26
  format.html
26
27
  format.svg { render :qrcode => request.url, :level => :l, :unit => 10 }
27
- format.png { render :qrcode => request.url }
28
+ format.png { render :qrcode => request.url, :bg => bg_image, :bsize => "200x100", :gravity => "center" }
28
29
  format.gif { render :qrcode => request.url }
29
30
  format.jpeg { render :qrcode => request.url }
30
31
  end
@@ -43,7 +44,8 @@ end
43
44
  * `:fill` – Background color (e.g "ffffff" or :white)
44
45
  * `:color` – Foreground color for the code (e.g. "000000" or :black)
45
46
  * `:bg` – Background image to be combined with QR code image (e.g. "./img/000.png")
46
- * `:gravity` Location where QR code image will be put on the background image (e.g. "center" or "north")
47
+ * `:bsize` Resize background image (e.g. "300x200")
48
+ * `:gravity` – Location where QR code image will be put on the background image (e.g. "center", "north", "south")
47
49
 
48
50
  ## About
49
51
 
@@ -17,38 +17,30 @@ module RQRCode
17
17
  level = options[:level] || :h
18
18
 
19
19
  bg = options[:bg] || false
20
-
20
+ bsize = options[:bsize] || false
21
+
21
22
  qrcode = RQRCode::QRCode.new(string, :size => size, :level => level)
22
23
  svg = RQRCode::Renderers::SVG::render(qrcode, options)
23
24
 
24
25
  data = \
25
26
  if format && format == :svg
26
- svg
27
+ svg
27
28
  else
28
29
  image = MiniMagick::Image.read(svg) { |i| i.format "svg" }
29
30
  image.format format
30
31
 
31
- #image = RQRCode::mergeImages(image, bg) if bg
32
32
  if bg
33
- print "=============================="
34
33
  bg_image = MiniMagick::Image.open bg
35
- gravity = options[:gravity] || "north"
36
- image = bg_image.composite(image) do |c|
34
+ bg_image.resize bsize if bsize
35
+ gravity = options[:gravity] || "north"
36
+ image = bg_image.composite(image) do |c|
37
37
  c.gravity gravity
38
38
  end
39
39
  end
40
40
 
41
- image.to_blob
41
+ image.to_blob
42
42
  end
43
43
 
44
44
  self.response_body = render_to_string(:text => data, :template => nil)
45
45
  end
46
-
47
- def mergeImages(image, bg, options)
48
- bg_image = MiniMagick::Image.open bg
49
- gravity = options[:gravity] || "north"
50
- bg_image.composite(image) do |c|
51
- c.gravity gravity
52
- end
53
- end
54
46
  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.2
4
+ version: 0.0.3
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-06-30 00:00:00.000000000 Z
11
+ date: 2013-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rqrcode