qr4r 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,21 +14,45 @@ In your code, add
14
14
 
15
15
  To use it:
16
16
 
17
- Qr4r::encode(input_string, output_file_path, size = 3)
17
+ Qr4r::encode(input_string, output_file_path, options)
18
18
 
19
- *input_string* and *output_file_path* should be strings. Size should be an integer from 1 - 10. The final output size is square and will be 33 * size pixels. e.g. if size = 4, the image will be 132x132. Default size is 3 (images are 99x99 pixels).
19
+ *input_string* and *output_file_path* should be strings. Options should a list of hash options keyed by symbols. Possible options are:
20
+
21
+ * :pixel_size - specify the size of each 'black' dot in the qrcode. Default = 3
22
+ * :border - specify the number of pixels to use for a white border around the outside. Default = 0
23
+ * :size - used by the qr code generation. A lower number means a smaller overall image. But it also means that you can encode fewer characters. This is computeed for you by default based on the input string size. You should not need to adjust it.
20
24
 
21
- NOTE: strings to be encoded are currently limited to 34 characters
22
25
  To encode the string 'qr codes are the new hotness' like this:
23
-
24
- string_to_encode = 'qr codes are the new hotness'
25
- Qr4r::encode(string_to_encode, 'qrcode.out.png')
26
26
 
27
- Not happy with the default size (99px x 99px)? Adjust the size with the 3rd argument to encode
27
+ require 'qr4r'
28
+ s = 'qr codes are the new hotness'
29
+ fname = s.gsub(/\s+/,"_") + ".qr.png"
30
+ Qr4r::encode(s, fname)
31
+
32
+ Make a bigger QRCode
33
+
34
+ s = 'big qr codes are the new hotness'
35
+ fname = s.gsub(/\s+/,"_") + ".qr.png"
36
+ Qr4r::encode(s, fname, :pixel_size => 5)
37
+
38
+ Add a fat border
39
+
40
+ s = 'big qr codes are the new hotness with a border'
41
+ fname = s.gsub(/\s+/,"_") + ".qr.png"
42
+ Qr4r::encode(s, fname, :border => 20)
43
+
44
+
45
+ ## Authors
46
+
47
+ Original author: [Jon Rogers](http://github.com/bunnymatic) [at 2rye](http://2rye.com)
28
48
 
29
- # the following produces an image who's size is 165px x 165px
30
- string_to_encode = 'big qr codes are the new hotness'
31
- Qr4r::encode(string_to_encode, 'qrcode.out.png', 5)
49
+ Thanks to [Duncan Robertson](http://whomwah.github.com/rqrcode/) for writing rQRCode
32
50
 
51
+ ## Contributing
52
+ * Fork the project
53
+ * Send a pull request
54
+ * Don't bump the version or modify the gemspec. I'll do that when I merge in your mods and release a new version.
33
55
 
56
+ ## Copyright
34
57
 
58
+ MIT Licence (http://www.opensource.org/licenses/mit-license.html)
data/Rakefile CHANGED
@@ -13,5 +13,6 @@ task :test do
13
13
  end
14
14
 
15
15
  task :build do
16
+ `rm qr4r-*.gem`
16
17
  puts `gem build qr4r.gemspec`
17
18
  end
data/lib/qr4r.rb CHANGED
@@ -48,15 +48,16 @@ module Qr4r
48
48
  MojoMagick::convert do |c|
49
49
  d = data.pack 'C'*data.size
50
50
  c.blob(d, :format => :rgb, :depth => 8, :size => ("%dx%d" % [qr.modules.size, qr.modules.size]))
51
- c.file outfile
52
- end
53
- if opts[:pixel_size]
54
- MojoMagick::convert do |c|
51
+ if opts[:pixel_size]
55
52
  wd = qr.modules.size * opts[:pixel_size].to_i
56
- c.file outfile
57
53
  c.scale "%dx%d" % [ wd, wd ]
58
- c.file outfile
59
54
  end
55
+ if opts[:border]
56
+ border = opts[:border].to_i
57
+ c.bordercolor '"#ffffff"'
58
+ c.border '%dx%d' % [ border, border ]
59
+ end
60
+ c.file outfile
60
61
  end
61
62
  end
62
63
 
data/lib/qr4r/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qr4r
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.3'
3
3
  end
data/test/qr4r_test.rb CHANGED
@@ -25,6 +25,17 @@ class Qr4rTest < Test::Unit::TestCase
25
25
  assert r[:width] == 33 * 3
26
26
  end
27
27
 
28
+ def test_encode_with_size_and_border
29
+ # do something
30
+ f = Tempfile.new(['qr4r','.png'])
31
+ Qr4r::encode('whatever yo', f.path, :size => 4, :border => 10)
32
+ # assert that it worked
33
+ assert File.exists?(f)
34
+ r = MojoMagick::get_image_size(f.path)
35
+ assert r[:height] == 33 * 3 + 20
36
+ assert r[:width] == 33 * 3 + 20
37
+ end
38
+
28
39
  def test_encode_with_pixel_size
29
40
  # do something
30
41
  f = Tempfile.new(['qr4r','.png'])
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: qr4r
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.1
5
+ version: 0.3.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jon Rogers
@@ -92,6 +92,6 @@ rubyforge_project: qr4r
92
92
  rubygems_version: 1.8.15
93
93
  signing_key:
94
94
  specification_version: 3
95
- summary: qr4r-0.3.1
95
+ summary: qr4r-0.3.3
96
96
  test_files:
97
97
  - test/qr4r_test.rb