Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 54835dc

Browse files
committedMar 19, 2012
* add ability to add :border
* more efficient processing of border and pixel size * update readme with credits/authors and border parameter info * add 'rm qr4r*.gem' to build task in rake
1 parent e978c28 commit 54835dc

File tree

5 files changed

+51
-16
lines changed

5 files changed

+51
-16
lines changed
 

‎README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,41 @@ To use it:
1818

1919
*input_string* and *output_file_path* should be strings. Options should a list of hash options keyed by symbols. Possible options are:
2020

21-
* :pixel_size - this is used to specify the size of each 'black' dot in the qrcode. Default = 3
22-
* :size - this is 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.
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.
2324

2425
To encode the string 'qr codes are the new hotness' like this:
25-
26-
string_to_encode = 'qr codes are the new hotness'
27-
Qr4r::encode(string_to_encode, 'qrcode.out.png')
2826

29-
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)
3048

31-
# the following produces an image who's size is 165px x 165px
32-
string_to_encode = 'big qr codes are the new hotness'
33-
Qr4r::encode(string_to_encode, 'qrcode.out.png', :pixel_size => 5)
49+
Thanks to [Duncan Robertson](http://whomwah.github.com/rqrcode/) for writing rQRCode
3450

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.
3555

56+
## Copyright
3657

58+
MIT Licence (http://www.opensource.org/licenses/mit-license.html)

‎Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ task :test do
1313
end
1414

1515
task :build do
16+
`rm qr4r-*.gem`
1617
puts `gem build qr4r.gemspec`
1718
end

‎lib/qr4r.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@ def self.encode(str, outfile, *rest)
4848
MojoMagick::convert do |c|
4949
d = data.pack 'C'*data.size
5050
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]
5552
wd = qr.modules.size * opts[:pixel_size].to_i
56-
c.file outfile
5753
c.scale "%dx%d" % [ wd, wd ]
58-
c.file outfile
5954
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
6061
end
6162
end
6263

‎lib/qr4r/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Qr4r
2-
VERSION = '0.3.1'
2+
VERSION = '0.3.3'
33
end

‎test/qr4r_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ def test_encode_with_size
2525
assert r[:width] == 33 * 3
2626
end
2727

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+
2839
def test_encode_with_pixel_size
2940
# do something
3041
f = Tempfile.new(['qr4r','.png'])

0 commit comments

Comments
 (0)
Failed to load comments.