rqrcode_png 0.0.1
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.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/LICENSE +18 -0
- data/README.markdown +27 -0
- data/Rakefile +1 -0
- data/lib/rqrcode_png.rb +8 -0
- data/lib/rqrcode_png/image.rb +39 -0
- data/lib/rqrcode_png/qrcode_extensions.rb +25 -0
- data/lib/rqrcode_png/version.rb +3 -0
- data/rqrcode_png.gemspec +24 -0
- metadata +77 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2011 Dan Carper
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# rqrcode_png
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
rQRcode is a great library that generates the 2D sequence of a QR code, and chunky_png is a great pure ruby library for generating and manipulating images.
|
5
|
+
|
6
|
+
rqrcode_png ties the two libraries together. rqrcode_png assumes as little as possible.
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
qrqcode_png extends RQRCode::QRCode with one simple method, #to_img.
|
10
|
+
|
11
|
+
\#to_img returns an instance of ChunkyPNG. The image itself is 37x37 pixels which includes a 2 pixel border, which can easily be resized and saved.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
|
15
|
+
png = qr.to_img
|
16
|
+
png.resize(90, 90).save("really_cool_qr_image.png") # ChunkyPNG methods
|
17
|
+
```
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
* Fork the project
|
21
|
+
* Send a pull request
|
22
|
+
* Don't touch the .gemspec, I'll do that when I release a new version
|
23
|
+
|
24
|
+
## Copyright
|
25
|
+
|
26
|
+
MIT Licence (http://www.opensource.org/licenses/mit-license.html)
|
27
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/rqrcode_png.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module RQRCodePNG
|
2
|
+
class Image
|
3
|
+
BORDER = 2
|
4
|
+
IMG_SIZE = 33
|
5
|
+
TOTAL_IMG_SIZE = IMG_SIZE + BORDER * 2
|
6
|
+
BLACK = ::ChunkyPNG::Color::BLACK
|
7
|
+
WHITE = ::ChunkyPNG::Color::WHITE
|
8
|
+
|
9
|
+
attr_accessor :qr_code
|
10
|
+
|
11
|
+
def initialize(qr_code)
|
12
|
+
self.qr_code = qr_code
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Returns an image file of the QR Code
|
17
|
+
#
|
18
|
+
def render
|
19
|
+
png = blank_img()
|
20
|
+
|
21
|
+
qr_code().dark_squares_only do |x, y|
|
22
|
+
png[y + BORDER, x + BORDER] = BLACK
|
23
|
+
end
|
24
|
+
|
25
|
+
return png
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
#
|
31
|
+
# Returns an appropriately sized, blank (white) image
|
32
|
+
#
|
33
|
+
def blank_img
|
34
|
+
::ChunkyPNG::Image.new( TOTAL_IMG_SIZE,
|
35
|
+
TOTAL_IMG_SIZE,
|
36
|
+
WHITE )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RQRCodePNG
|
2
|
+
|
3
|
+
module QRCodeExtensions
|
4
|
+
# This method returns a 33x33 .png of the code
|
5
|
+
#
|
6
|
+
def to_img
|
7
|
+
return Image.new(self).render()
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# This method yields the vertices of the dark squares
|
12
|
+
#
|
13
|
+
def dark_squares_only(&block)
|
14
|
+
self.modules.each_index do |row|
|
15
|
+
self.modules.each_index do |column|
|
16
|
+
if self.dark?(row, column)
|
17
|
+
yield row, column
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/rqrcode_png.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rqrcode_png/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rqrcode_png"
|
7
|
+
s.version = RqrcodePng::VERSION
|
8
|
+
s.authors = ["Dan Carper"]
|
9
|
+
s.email = ["dcarper@dreamagile.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Produces a .png from a given QR Code}
|
12
|
+
s.description = %q{Glues rQRCode together with chunky_png}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rqrcode_png"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "chunky_png"
|
22
|
+
s.add_dependency "rqrcode"
|
23
|
+
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rqrcode_png
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Carper
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-08 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: chunky_png
|
16
|
+
requirement: &2157538300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157538300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rqrcode
|
27
|
+
requirement: &2157537880 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157537880
|
36
|
+
description: Glues rQRCode together with chunky_png
|
37
|
+
email:
|
38
|
+
- dcarper@dreamagile.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.markdown
|
47
|
+
- Rakefile
|
48
|
+
- lib/rqrcode_png.rb
|
49
|
+
- lib/rqrcode_png/image.rb
|
50
|
+
- lib/rqrcode_png/qrcode_extensions.rb
|
51
|
+
- lib/rqrcode_png/version.rb
|
52
|
+
- rqrcode_png.gemspec
|
53
|
+
homepage: ''
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project: rqrcode_png
|
73
|
+
rubygems_version: 1.8.8
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Produces a .png from a given QR Code
|
77
|
+
test_files: []
|