tianji_qrcode_png 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
6
+ *.wo
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rqrcode_png.gemspec
4
+ gemspec
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/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ module TianjiQRCodePNG
2
+ class Image
3
+ BLACK = ::ChunkyPNG::Color::BLACK
4
+ WHITE = ::ChunkyPNG::Color::WHITE
5
+ TRANSPARENT = ::ChunkyPNG::Color::TRANSPARENT
6
+
7
+ def initialize(qr_code)
8
+ @sequence = Sequence.new(qr_code)
9
+ end
10
+
11
+ #重写render方法,加入二维码颜色和边框参数
12
+ def render(bg_color, color, border)
13
+ @sequence.border = border.to_i
14
+ png = blank_img(bg_color)
15
+ @sequence.dark_squares_only do |x, y|
16
+ png[y + @sequence.border_width(), x + @sequence.border_width()] = color
17
+ end
18
+ return png
19
+ end
20
+
21
+ private
22
+
23
+ # Returns the size of the image
24
+ def img_size()
25
+ @img_size ||= @sequence.img_size() + @sequence.border_width() * 2
26
+ end
27
+
28
+ # Returns an appropriately sized, blank (white) image
29
+ def blank_img bg_color = WHITE
30
+ ::ChunkyPNG::Image.new(img_size(), img_size(), bg_color)
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,9 @@
1
+ module TianjiQRCodePNG
2
+ module QRCodeExtensions
3
+ #to_img方法,加入二维码颜色和边框参数
4
+ def to_img(bg_color = ChunkyPNG::Color::TRANSPARENT, color = ChunkyPNG::Color::BLACK, border = 1)
5
+ return Image.new(self).render(bg_color, color, border)
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,31 @@
1
+ module TianjiQRCodePNG
2
+ class Sequence
3
+ attr_accessor :border
4
+
5
+ def initialize(qr_code)
6
+ @qr_code = qr_code
7
+ end
8
+
9
+ # This method yields the vertices of the dark squares
10
+ def dark_squares_only(&block)
11
+ @qr_code.modules.each_index do |row|
12
+ @qr_code.modules.each_index do |column|
13
+ if @qr_code.dark?(row, column)
14
+ yield row, column
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ # returns the image size by looking at how long the first line of the code is
21
+ def img_size
22
+ @img_size ||= @qr_code.to_s.split("\n").first.size()
23
+ end
24
+
25
+ # Returns the border, 1/10 of the img size
26
+ def border_width()
27
+ @border ||= img_size() / 10
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,4 @@
1
+ module TianjiQRCodePNG
2
+ VERSION = "0.0.3"
3
+ end
4
+
@@ -0,0 +1,9 @@
1
+ require 'chunky_png'
2
+ require 'rqrcode'
3
+
4
+ require 'tianji_qrcode_png/version'
5
+ require 'tianji_qrcode_png/sequence'
6
+ require 'tianji_qrcode_png/image'
7
+ require 'tianji_qrcode_png/qrcode_extensions'
8
+
9
+ QRCode::QRCode.send :include, TianjiQRCodePNG::QRCodeExtensions
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tianji_qrcode_png/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tianji_qrcode_png"
7
+ s.version = TianjiQRCodePNG::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 = "tianji_qrcode_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 CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tianji_qrcode_png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -49,13 +49,23 @@ email:
49
49
  executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
- files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - Rakefile
57
+ - lib/tianji_qrcode_png.rb
58
+ - lib/tianji_qrcode_png/image.rb
59
+ - lib/tianji_qrcode_png/qrcode_extensions.rb
60
+ - lib/tianji_qrcode_png/sequence.rb
61
+ - lib/tianji_qrcode_png/version.rb
62
+ - tianji_qrcode_png.gemspec
53
63
  homepage: ''
54
64
  licenses: []
55
65
  post_install_message:
56
66
  rdoc_options: []
57
67
  require_paths:
58
- - lib
68
+ - ../lib
59
69
  required_ruby_version: !ruby/object:Gem::Requirement
60
70
  none: false
61
71
  requirements: