rqrcode_png_with_fixes 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '083aaa11258af98ff43696848d0c7c282dd33fe40d318b89a6db6b200ece9ad6'
4
+ data.tar.gz: 7acf6e2a8474abb0e1009b8b3491834edc5e8b45e3b5100e1d5dda61266b5c5a
5
+ SHA512:
6
+ metadata.gz: c6154659312c341d4b0c44095d8d8ff162001a7077ee5be97902b8a4663623828480fb3b3bf7aff4371cdfd317c29e720a4818ad5cfe8b5ed293329111819781
7
+ data.tar.gz: d4028a772e34e27ee90d2602b71c4cf340d5257c9dddbe955e92f82f4893505d51efb116d69fd93a048b4b3817758d0774cbadc79018f07536b730d231a5a964
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/README.markdown ADDED
@@ -0,0 +1,62 @@
1
+ # rqrcode_png
2
+ **Problem:** You need to generate your own QR code images
3
+ **Solution:** rqrcode_png
4
+
5
+ ## Overview
6
+ rqrcode_png extends [rqrcode](https://github.com/whomwah/rqrcode), adding one simple method to instances of QRCode, **\#to_img**. [ChunkyPNG](https://github.com/wvanbergen/chunky_png) is used to generate the image itself in pure Ruby. As few assumptions are made as possible regarding the image itself.
7
+
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ require 'rqrcode_png'
13
+
14
+ qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
15
+ png = qr.to_img # returns an instance of ChunkyPNG
16
+ png.resize(90, 90).save("really_cool_qr_image.png")
17
+ ```
18
+
19
+ *NOTE:* For now, the :size of the QR code has to be 14 or less. Working on this.
20
+
21
+ ### Bundler
22
+ ```ruby
23
+ gem 'rqrcode_png'
24
+ ```
25
+
26
+ ### Rails
27
+
28
+ #### With [DragonFly](https://github.com/markevans/dragonfly)
29
+
30
+ ```ruby
31
+ # app/models/product.rb
32
+ class Product < ActiveRecord::Base
33
+ dragonfly_accessor :qr_code
34
+ end
35
+ ```
36
+
37
+ ```ruby
38
+ # somewhere
39
+ qr_code_img = RQRCode::QRCode.new('http://www.google.com/', :size => 4, :level => :h ).to_img
40
+ @product.update_attribute :qr_code, qr_code_img.to_string
41
+ ```
42
+
43
+ ```ruby
44
+ # app/controllers/products.rb
45
+ def show
46
+ @product = Product.find(params[:id])
47
+ end
48
+ ```
49
+
50
+ ```ruby
51
+ # app/views/products/show.html.erb
52
+ <%= image_tag @product.qr_code.url %>
53
+ ```
54
+
55
+ ## Contributing
56
+ * Fork the project
57
+ * Send a pull request
58
+ * Don't touch the .gemspec, I'll do that when I release a new version
59
+
60
+ ## Copyright
61
+ MIT Licence (http://www.opensource.org/licenses/mit-license.html)
62
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ module RQRCodePNG
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
+ # Returns an image file of the QR Code
12
+ def render bg_color = WHITE
13
+ png = blank_img(bg_color)
14
+ @sequence.dark_squares_only do |x, y|
15
+ png[y + @sequence.border_width(), x + @sequence.border_width()] = BLACK
16
+ end
17
+ return png
18
+ end
19
+
20
+ private
21
+
22
+ # Returns the size of the image
23
+ def img_size()
24
+ @img_size ||= @sequence.img_size() + @sequence.border_width() * 2
25
+ end
26
+
27
+ # Returns an appropriately sized, blank (white) image
28
+ def blank_img bg_color = WHITE
29
+ ::ChunkyPNG::Image.new(img_size(), img_size(), bg_color)
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,9 @@
1
+ module RQRCodePNG
2
+ module QRCodeExtensions
3
+ # This method returns a 33x33 .png of the code
4
+ def to_img(bg_color = ChunkyPNG::Color::WHITE)
5
+ return Image.new(self).render(bg_color)
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,29 @@
1
+ module RQRCodePNG
2
+ class Sequence
3
+ def initialize(qr_code)
4
+ @qr_code = qr_code
5
+ end
6
+
7
+ # This method yields the vertices of the dark squares
8
+ def dark_squares_only(&block)
9
+ @qr_code.modules.each_index do |row|
10
+ @qr_code.modules.each_index do |column|
11
+ if @qr_code.dark?(row, column)
12
+ yield row, column
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ # returns the image size by looking at how long the first line of the code is
19
+ def img_size
20
+ @img_size ||= @qr_code.to_s.split("\n").first.size()
21
+ end
22
+
23
+ # Returns the border, 1/10 of the img size
24
+ def border_width()
25
+ @border ||= img_size() / 10
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,4 @@
1
+ module RqrcodePng
2
+ VERSION = "0.1.6"
3
+ end
4
+
@@ -0,0 +1,9 @@
1
+ require 'chunky_png'
2
+ require 'rqrcode'
3
+
4
+ require 'rqrcode_png/version'
5
+ require 'rqrcode_png/sequence'
6
+ require 'rqrcode_png/image'
7
+ require 'rqrcode_png/qrcode_extensions'
8
+
9
+ RQRCode::QRCode.send :include, RQRCodePNG::QRCodeExtensions
@@ -0,0 +1,26 @@
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_with_fixes"
7
+ s.version = RqrcodePng::VERSION
8
+ s.authors = ["Aleksandr Movsesyan"]
9
+ s.email = ["amovsesy@gmail.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
+ s.licenses = ['MIT']
14
+
15
+ s.rubyforge_project = "rqrcode_png"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rake"
23
+ s.add_dependency "chunky_png"
24
+ s.add_dependency "rqrcode", "< 1.0.0"
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rqrcode_png_with_fixes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
5
+ platform: ruby
6
+ authors:
7
+ - Aleksandr Movsesyan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chunky_png
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rqrcode
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ description: Glues rQRCode together with chunky_png
56
+ email:
57
+ - amovsesy@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE
65
+ - README.markdown
66
+ - Rakefile
67
+ - lib/rqrcode_png.rb
68
+ - lib/rqrcode_png/image.rb
69
+ - lib/rqrcode_png/qrcode_extensions.rb
70
+ - lib/rqrcode_png/sequence.rb
71
+ - lib/rqrcode_png/version.rb
72
+ - rqrcode_png.gemspec
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.1.4
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Produces a .png from a given QR Code
96
+ test_files: []