rqrcode 0.10.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +2 -0
  5. data/CHANGELOG.md +60 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +68 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +223 -135
  10. data/Rakefile +10 -0
  11. data/_config.yml +1 -0
  12. data/bin/console +14 -0
  13. data/images/ansi-screen-shot.png +0 -0
  14. data/images/github-qrcode.png +0 -0
  15. data/images/github-qrcode.svg +32 -0
  16. data/lib/rqrcode/export/ansi.rb +22 -25
  17. data/lib/rqrcode/export/html.rb +8 -10
  18. data/lib/rqrcode/export/png.rb +62 -45
  19. data/lib/rqrcode/export/svg.rb +180 -24
  20. data/lib/rqrcode/export.rb +6 -0
  21. data/lib/rqrcode/qrcode/qrcode.rb +17 -0
  22. data/lib/rqrcode/qrcode.rb +3 -4
  23. data/lib/rqrcode/version.rb +3 -1
  24. data/lib/rqrcode.rb +8 -19
  25. data/rqrcode.gemspec +39 -0
  26. metadata +90 -60
  27. data/CHANGELOG +0 -97
  28. data/LICENSE +0 -19
  29. data/lib/rqrcode/core_ext/array/behavior.rb +0 -12
  30. data/lib/rqrcode/core_ext/array.rb +0 -5
  31. data/lib/rqrcode/core_ext/integer/bitwise.rb +0 -13
  32. data/lib/rqrcode/core_ext/integer.rb +0 -5
  33. data/lib/rqrcode/core_ext.rb +0 -5
  34. data/lib/rqrcode/qrcode/qr_8bit_byte.rb +0 -36
  35. data/lib/rqrcode/qrcode/qr_alphanumeric.rb +0 -47
  36. data/lib/rqrcode/qrcode/qr_bit_buffer.rb +0 -99
  37. data/lib/rqrcode/qrcode/qr_code.rb +0 -585
  38. data/lib/rqrcode/qrcode/qr_math.rb +0 -63
  39. data/lib/rqrcode/qrcode/qr_numeric.rb +0 -57
  40. data/lib/rqrcode/qrcode/qr_polynomial.rb +0 -78
  41. data/lib/rqrcode/qrcode/qr_rs_block.rb +0 -314
  42. data/lib/rqrcode/qrcode/qr_util.rb +0 -272
  43. data/test/data.rb +0 -25
  44. data/test/test_helper.rb +0 -5
  45. data/test/test_regresions.rb +0 -10
  46. data/test/test_rqrcode.rb +0 -155
  47. data/test/test_rqrcode_export.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 26f31be7d65a2c99f43c5f32b04624dd6ccf214e
4
- data.tar.gz: 4e102fa21c4509cd243bc175cb0d4f0093e4a009
2
+ SHA256:
3
+ metadata.gz: a7f00d7af65a23ac1eeebda231f79607353d52c8b6b83072b53642fbcf5c4b88
4
+ data.tar.gz: a7cc3db7028ab710f6b325cbd76a91db4da23b889f65252f1faa99cfc319512f
5
5
  SHA512:
6
- metadata.gz: dd864e4980b78fcfcc4b3c142fea0ee5205599eabfc74f3c9b16023b9c3d7505131dcfe78c4067e59672ffd0bfadd53db1a29a0b57eab6bd953e0c7f309a1cb3
7
- data.tar.gz: 10404efce4d90af63ab2f302f65243ceca285e736350d032acd5d48cf9b9fb768b67d5bf574e31a267f3b214cf0419cbfde6987fc12505282970628bf23da0cc
6
+ metadata.gz: 328a1114929797f4a47e0101055afe1e73f7fc9b015ca8435069aecdecff29699f9c694e158bca0aff52003b8b0cb8072a1296fee48a93bea00c55a1d0c565ba
7
+ data.tar.gz: e6b0bbdc6e99265e6d9b00260bb55a4c92669cadff5720d93fca5d2f450002d3f885772377eeb8191468853b17fde9c834db6d27aafd20609b3dd2c95c4ec958
@@ -0,0 +1,28 @@
1
+ name: rqrcode
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ Build:
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: [ubuntu-latest, macos-latest]
17
+ ruby: [2.5, 2.6, 2.7, '3.0', 3.1]
18
+ runs-on: ${{ matrix.os }}
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
25
+ - name: Run Tests for Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
26
+ run: bundle exec rake spec
27
+ - name: StandardRB check for Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
28
+ run: bundle exec standardrb --format progress
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.devcontainer/
10
+ .rvmrc
11
+ *.sublime-project
12
+ *.sublime-workspace
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [2.1.2] - 2022-07-26
11
+
12
+ * Remove setup script as it just calls bundle install [#128]
13
+ * Change inline styles to the fill property to allow for strict CSP style-src directive [#127]
14
+
15
+ ## [2.1.1] - 2022-02-11
16
+
17
+ - Added in a handler for when color arguments are passed in as symbols e.g `color: :yellow`. This also allows for the use of the `:currentColor` keyword. [#122]
18
+
19
+ ## [2.1.0] - 2021-08-26
20
+
21
+ - Sync Gemfile.lock with `rqrcode_core.1.2.0` [Adds Multimode Support](https://github.com/whomwah/rqrcode_core#multiple-encoding-support)
22
+ - Add badge for Standard linting
23
+
24
+ ### Changed
25
+
26
+ - Corrected method name referred to in CHANGELOG.
27
+
28
+ ## [2.0.0] - 2021-05-06
29
+
30
+ ### Added
31
+
32
+ - A new `use_path:` option on `.as_svg`. This uses a `<path>` node to greatly reduce the final SVG size. [#108]
33
+ - A new `viewbox:` option on `.as_svg`. Replaces the `svg.width` and `svg.height` attribute with `svg.viewBox` to allow CSS scaling. [#112]
34
+ - A new `svg_attributes:` option on `.as_svg`. Allows you to pass in custom SVG attributes to be used in the `<svg>` tag. [#113]
35
+
36
+ ### Changed
37
+
38
+ - README updated
39
+ - Rakefile cleaned up. You can now just run `rake` which will run specs and fix linting using `standardrb`
40
+ - Small documentation clarification [@smnscp](https://github.com/smnscp)
41
+ - Bump `rqrcode_core` to `~> 1.0`
42
+
43
+ ### Breaking Change
44
+
45
+ - The dependency `rqrcode_core-1.0.0` has a tiny breaking change to the `to_s` public method. https://github.com/whomwah/rqrcode_core/blob/master/CHANGELOG.md#breaking-changes
46
+
47
+ ## [1.2.0] - 2020-12-26
48
+
49
+ ### Changed
50
+
51
+ - README updated
52
+ - bump dependencies
53
+ - fix `required_ruby_version` for Ruby 3 support
54
+
55
+ [unreleased]: https://github.com/whomwah/rqrcode/compare/v2.1.2...HEAD
56
+ [2.1.2]: https://github.com/whomwah/rqrcode/compare/v2.1.1...v2.1.2
57
+ [2.1.1]: https://github.com/whomwah/rqrcode/compare/v2.1.0...v2.1.1
58
+ [2.1.0]: https://github.com/whomwah/rqrcode/compare/v2.0.0...v2.1.0
59
+ [2.0.0]: https://github.com/whomwah/rqrcode/compare/v1.2.0...v2.0.0
60
+ [1.2.0]: https://github.com/whomwah/rqrcode/compare/v1.1.1...v1.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rqrcode-base.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rqrcode (2.1.2)
5
+ chunky_png (~> 1.0)
6
+ rqrcode_core (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ chunky_png (1.4.0)
13
+ diff-lcs (1.4.4)
14
+ parallel (1.21.0)
15
+ parser (3.1.0.0)
16
+ ast (~> 2.4.1)
17
+ rainbow (3.0.0)
18
+ rake (13.0.3)
19
+ regexp_parser (2.2.0)
20
+ rexml (3.2.5)
21
+ rqrcode_core (1.2.0)
22
+ rspec (3.10.0)
23
+ rspec-core (~> 3.10.0)
24
+ rspec-expectations (~> 3.10.0)
25
+ rspec-mocks (~> 3.10.0)
26
+ rspec-core (3.10.1)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-expectations (3.10.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-mocks (3.10.2)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-support (3.10.2)
35
+ rubocop (1.24.1)
36
+ parallel (~> 1.10)
37
+ parser (>= 3.0.0.0)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ regexp_parser (>= 1.8, < 3.0)
40
+ rexml
41
+ rubocop-ast (>= 1.15.1, < 2.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 1.4.0, < 3.0)
44
+ rubocop-ast (1.15.1)
45
+ parser (>= 3.0.1.1)
46
+ rubocop-performance (1.13.1)
47
+ rubocop (>= 1.7.0, < 2.0)
48
+ rubocop-ast (>= 0.4.0)
49
+ ruby-progressbar (1.11.0)
50
+ standard (1.6.0)
51
+ rubocop (= 1.24.1)
52
+ rubocop-performance (= 1.13.1)
53
+ standardrb (1.0.0)
54
+ standard
55
+ unicode-display_width (2.1.0)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 2.0)
62
+ rake (~> 13.0)
63
+ rqrcode!
64
+ rspec (~> 3.5)
65
+ standardrb (~> 1.0)
66
+
67
+ BUNDLED WITH
68
+ 2.2.32
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2008 Duncan Robertson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,217 +1,305 @@
1
- # rQRCode, Encode QRCodes
1
+ # RQRCode
2
2
 
3
- [![Build Status](https://travis-ci.org/whomwah/rqrcode.svg?branch=master)](https://travis-ci.org/whomwah/rqrcode)
3
+ ![](https://github.com/whomwah/rqrcode/actions/workflows/ruby.yml/badge.svg)
4
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
4
5
 
5
- **All users of rqrcode are highly recomended to upgrade to version 0.5.5 ore later!**
6
6
 
7
- ## Short changelog
7
+ [RQRCode](https://github.com/whomwah/rqrcode) is a library for creating and rendering QR codes into various formats. It has a simple interface with all the standard QR code options. It was adapted from the Javascript library by Kazuhiko Arase.
8
8
 
9
- *0.10.1* (Feb 11, 2016)
9
+ * QR code is trademarked by Denso Wave inc
10
+ * Minimum Ruby version is `>= 2.3`
11
+ * For `rqrcode` releases `< 2.0.0` please use [this README](https://github.com/whomwah/rqrcode/blob/v1.2.0/README.md)
12
+ * For `rqrcode` releases `< 1.0.0` please use [this README](https://github.com/whomwah/rqrcode/blob/v0.9.0/README.md)
10
13
 
11
- - Changed so that gem wont include images and tests.
14
+ ## Installing
12
15
 
13
- *0.10.0* (Feb 11, 2016)
16
+ Add this line to your application's `Gemfile`:
14
17
 
15
- - Merged as_ansi by [Andy Brody](https://github.com/ab)
18
+ ```ruby
19
+ gem "rqrcode", "~> 2.0"
20
+ ```
16
21
 
17
- *0.9.0* (Jan 3, 2016)
22
+ or install manually:
18
23
 
19
- - Added support for auto selecting qrcode size up to level 40. (only worked up to level 10 before)
20
- - Added numeric support during auto selection of qrcode mode.
24
+ ```ruby
25
+ gem install rqrcode
26
+ ```
21
27
 
22
- *0.8.1* (Jan 3, 2016)
28
+ ## Basic usage example
23
29
 
24
- - Remove active support specific `present?`.
25
- - Fix so that all tests are run.
30
+ ```ruby
31
+ require "rqrcode"
26
32
 
27
- *0.8.0* (Dec 18, 2015)
33
+ qr = RQRCode::QRCode.new("https://kyan.com")
28
34
 
29
- - Added numeric QR code support
30
- - Dropped Ruby v1.8 support
35
+ puts qr.to_s
36
+ # to_s( dark: "x", light: " " ) # defaults
37
+
38
+ xxxxxxx xxxxxxx xxx xxxxxxx
39
+ x x x xxx xx x x
40
+ x xxx x xx x x xx x xxx x
41
+ x xxx x xx xx xx x xxx x
42
+ x xxx x x x xxx x xxx x
43
+ x x xxx x xx x x x x
44
+ ...
45
+ ```
31
46
 
32
- ## Overview
47
+ Easy, but unlikely to be readable. For this you will need to use one of the many [rendering options](#render-types) below.
33
48
 
34
- rQRCode is a library for encoding QR Codes in Ruby. It has a simple interface with all the standard qrcode options. It was adapted from the Javascript library by Kazuhiko Arase.
49
+ ### Advanced Options
35
50
 
36
- Let's clear up some rQRCode stuff.
51
+ These are the various QR code generation options provided by the underlying [rqrcode_core](https://github.com/whomwah/rqrcode_core). You may actually only need this library if you don't need the various rendering options `rqrcode` provides, but just need the data structure.
37
52
 
38
- * rQRCode is a __ruby only library__ It requires no native libraries. Just Ruby!
39
- * It is an encoding library. You can't decode QR codes with it.
40
- * The interface is simple and assumes you just want to encode a string into a QR code
41
- * QR code is trademarked by Denso Wave inc
53
+ ```
54
+ Expects a string or array (for multi-segment encoding) to be parsed in, other args are optional
42
55
 
43
- ## Installing
56
+ data - the string, QRSegment or array of Hashes (with data:, mode: keys) you wish to encode
44
57
 
45
- You may get the latest stable version from Rubygems.
58
+ size - the size (Integer) of the QR Code (defaults to smallest size needed to encode the data)
46
59
 
47
- ```ruby
48
- gem install rqrcode
60
+ max_size - the max_size (Integer) of the QR Code (default RQRCodeCore::QRUtil.max_size)
61
+
62
+ level - the error correction level, can be:
63
+ * Level :l 7% of code can be restored
64
+ * Level :m 15% of code can be restored
65
+ * Level :q 25% of code can be restored
66
+ * Level :h 30% of code can be restored (default :h)
67
+
68
+ mode - the mode of the QR Code (defaults to :alphanumeric or :byte_8bit, depending on the input data,
69
+ only used when data is a string):
70
+ * :number
71
+ * :alphanumeric
72
+ * :byte_8bit
73
+ * :kanji
49
74
  ```
50
75
 
51
- ## Using rQRCode
76
+ Example
52
77
 
53
78
  ```ruby
54
- require 'rqrcode'
79
+ simple_qrcode = RQRCodeCore::QRCode.new("https://kyan.com", size: 1, level: :m, mode: :alphanumeric)
55
80
 
56
- qrcode = RQRCode::QRCode.new("http://github.com/")
57
- image = qrcode.as_png
58
- svg = qrcode.as_svg
59
- html = qrcode.as_html
60
- string = qrcode.as_ansi
61
- string = qrcode.to_s
81
+ segment_qrcode = QRCodeCore::QRCode.new({ data: "foo", mode: :byte_8bit })
82
+
83
+ multi_qrcode = RQRCodeCore::QRCode.new([
84
+ { data: 'foo', mode: :byte_8bit },
85
+ { data: 'bar1', mode: :alphanumeric }
86
+ ])
62
87
  ```
63
88
 
64
- ## Image Rendering
65
- ### SVG
89
+ ## Render types
90
+
91
+ You probably want to output your QR code in a specific format. We make this easy by providing a bunch of formats to choose from below, each with their own set of options:
92
+
93
+ ### `as_svg`
66
94
 
67
95
  The SVG renderer will produce a stand-alone SVG as a `String`
68
96
 
97
+ ```
98
+ Options:
99
+
100
+ offset - Padding around the QR Code in pixels
101
+ (default 0)
102
+ fill - Background color e.g "ffffff" or :white or :currentColor
103
+ (default none)
104
+ color - Foreground color e.g "000" or :black or :currentColor
105
+ (default "000")
106
+ module_size - The Pixel size of each module
107
+ (defaults 11)
108
+ shape_rendering - SVG Attribute: auto | optimizeSpeed | crispEdges | geometricPrecision
109
+ (defaults crispEdges)
110
+ standalone - Whether to make this a full SVG file, or only an svg to embed in other svg
111
+ (default true)
112
+ use_path - Use <path> to render SVG rather than <rect> to significantly reduce size
113
+ and quality. This will become the default in future versions.
114
+ (default false)
115
+ viewbox - Replace the `svg.width` and `svg.height` attribute with `svg.viewBox` to
116
+ allow CSS scaling
117
+ (default false)
118
+ svg_attributes - A optional hash of custom <svg> attributes. Existing attributes will remain.
119
+ (default {})
120
+ ```
121
+ Example
69
122
  ```ruby
123
+ require "rqrcode"
124
+
70
125
  qrcode = RQRCode::QRCode.new("http://github.com/")
71
- # With default options specified explicitly
72
- svg = qrcode.as_svg(offset: 0, color: '000',
73
- shape_rendering: 'crispEdges',
74
- module_size: 11)
126
+
127
+ # NOTE: showing with default options specified explicitly
128
+ svg = qrcode.as_svg(
129
+ color: "000",
130
+ shape_rendering: "crispEdges",
131
+ module_size: 11,
132
+ standalone: true,
133
+ use_path: true
134
+ )
75
135
  ```
76
136
 
77
137
  ![QR code with github url](./images/github-qrcode.svg)
78
138
 
79
- ### ANSI
139
+ ### `as_png`
80
140
 
81
- The ANSI renderer will produce as a string with ANSI color codes.
141
+ The will produce a PNG using the [ChunkyPNG gem](https://github.com/wvanbergen/chunky_png). The result will be a `ChunkyPNG::Image` instance.
82
142
 
83
- ```ruby
84
- qrcode = RQRCode::QRCode.new("http://github.com/")
85
- # With default options specified explicitly
86
- svg = qrcode.as_ansi_(light: "\033[47m", dark: "\033[40m",
87
- fill_character: ' ',
88
- quiet_zone_size: 4)
89
143
  ```
144
+ Options:
90
145
 
91
- ![QR code with github url](./images/ansi-screen-shot.png)
146
+ fill - Background ChunkyPNG::Color, defaults to 'white'
147
+ color - Foreground ChunkyPNG::Color, defaults to 'black'
92
148
 
93
- ### PNG
149
+ When option :file is supplied you can use the following ChunkyPNG constraints:
94
150
 
95
- The library can produce a PNG. Result will be a `ChunkyPNG::Image` instance.
151
+ color_mode - The color mode to use. Use one of the ChunkyPNG::COLOR_* constants.
152
+ (defaults to 'ChunkyPNG::COLOR_GRAYSCALE')
153
+ bit_depth - The bit depth to use. This option is only used for indexed images.
154
+ (defaults to 1 bit)
155
+ interlace - Whether to use interlacing (true or false).
156
+ (defaults to ChunkyPNG default)
157
+ compression - The compression level for Zlib. This can be a value between 0 and 9, or a
158
+ Zlib constant like Zlib::BEST_COMPRESSION
159
+ (defaults to ChunkyPNG default)
96
160
 
97
- ```ruby
98
- qrcode = RQRCode::QRCode.new("http://github.com/")
99
- # With default options specified explicitly
100
- png = qrcode.as_png(
101
- resize_gte_to: false,
102
- resize_exactly_to: false,
103
- fill: 'white',
104
- color: 'black',
105
- size: 120,
106
- border_modules: 4,
107
- module_px_size: 6,
108
- file: nil # path to write
109
- )
110
- IO.write("/tmp/github-qrcode.png", png.to_s)
111
- ```
161
+ There are two sizing algorithms.
112
162
 
113
- ![QR code with github url](./images/github-qrcode.png)
163
+ * Original that can result in blurry and hard to scan images
164
+ * Google's Chart API inspired sizing that resizes the module size to fit within the given image size.
114
165
 
115
- ## HTML Rendering
116
- ### In your controller
117
- ```ruby
118
- @qr = RQRCode::QRCode.new( 'https://github.com/whomwah/rqrcode', :size => 4, :level => :h )
119
- ```
166
+ The Google one will be used when no options are given or when the new size option is used.
120
167
 
121
- ### In your view
122
- ```html
123
- <%= raw @qr.as_html %>
124
- ```
168
+ *Google Sizing*
125
169
 
126
- ### CSS
127
- ```css
128
- table {
129
- border-width: 0;
130
- border-style: none;
131
- border-color: #0000ff;
132
- border-collapse: collapse;
133
- }
170
+ size - Total size of PNG in pixels. The module size is calculated so it fits.
171
+ (defaults to 120)
172
+ border_modules - Width of white border around the modules.
173
+ (defaults to 4).
134
174
 
135
- td {
136
- border-left: solid 10px #000;
137
- padding: 0;
138
- margin: 0;
139
- width: 0px;
140
- height: 10px;
141
- }
175
+ -- DONT USE border_modules OPTION UNLESS YOU KNOW ABOUT THE QUIET ZONE NEEDS OF QR CODES --
142
176
 
143
- td.black { border-color: #000; }
144
- td.white { border-color: #fff; }
177
+ *Original Sizing*
178
+
179
+ module_px_size - Image size, in pixels.
180
+ border - Border thickness, in pixels
181
+
182
+ It first creates an image where 1px = 1 module, then resizes.
183
+ Defaults to 120x120 pixels, customizable by option.
145
184
  ```
146
-
147
- ## On the console
185
+
186
+ Example
148
187
 
149
188
  ```ruby
150
- qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
151
- puts qr.to_s
152
- ```
189
+ require "rqrcode"
153
190
 
154
- Output:
191
+ qrcode = RQRCode::QRCode.new("http://github.com/")
155
192
 
156
- ```
157
- xxxxxxx x x x x x xx xxxxxxx
158
- x x xxx xxxxxx xxx x x
159
- x xxx x xxxxx x xx x xxx x
160
- ... etc
193
+ # NOTE: showing with default options specified explicitly
194
+ png = qrcode.as_png(
195
+ bit_depth: 1,
196
+ border_modules: 4,
197
+ color_mode: ChunkyPNG::COLOR_GRAYSCALE,
198
+ color: "black",
199
+ file: nil,
200
+ fill: "white",
201
+ module_px_size: 6,
202
+ resize_exactly_to: false,
203
+ resize_gte_to: false,
204
+ size: 120
205
+ )
206
+
207
+ IO.binwrite("/tmp/github-qrcode.png", png.to_s)
161
208
  ```
162
209
 
163
- ## Doing your own rendering
164
- ```ruby
165
- qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )
166
- qr.modules.each do |row|
167
- row.each do |col|
168
- print col ? "X" : " "
169
- end
170
- print "\n"
171
- end
172
- ```
210
+ ![QR code with github url](./images/github-qrcode.png)
173
211
 
174
- ## Specifying QR code mode
175
212
 
176
- Sometimes you may want to specify the QR code mode explicitly.
213
+ ### `as_ansi`
177
214
 
178
- It is done via the `mode` option. Allowed values are: `number`, `alphanumeric` and `byte_8bit`.
215
+ The ANSI renderer will produce as a string with ANSI color codes.
179
216
 
217
+ ```
218
+ Options:
219
+
220
+ light - Foreground ANSI code
221
+ (default "\033[47m")
222
+ dark - Background ANSI code
223
+ (default "\033[40m")
224
+ fill_character - The written character
225
+ (default ' ')
226
+ quiet_zone_size - Padding around the edge
227
+ (default 4)
228
+ ```
229
+ Example
180
230
  ```ruby
181
- qr = RQRCode::QRCode.new( '1234567890', :size => 2, :level => :m, :mode => :number )
231
+ require "rqrcode"
232
+
233
+ qrcode = RQRCode::QRCode.new("http://github.com/")
234
+
235
+ # NOTE: showing with default options specified explicitly
236
+ svg = qrcode.as_ansi(
237
+ light: "\033[47m", dark: "\033[40m",
238
+ fill_character: " ",
239
+ quiet_zone_size: 4
240
+ )
182
241
  ```
183
242
 
243
+ ![QR code with github url](./images/ansi-screen-shot.png)
184
244
 
185
245
  ## API Documentation
186
246
 
187
247
  [http://www.rubydoc.info/gems/rqrcode](http://www.rubydoc.info/gems/rqrcode)
188
248
 
189
- ## Resources
249
+ ## Tests
190
250
 
191
- * wikipedia:: http://en.wikipedia.org/wiki/QR_Code
192
- * Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
193
- * kaywa:: http://qrcode.kaywa.com
251
+ You can run the test suite using:
194
252
 
195
- ## Authors
253
+ ```
254
+ $ bundle install
255
+ $ rake # runs specs and standard:fix
256
+ $ rake spec # just runs the specs
257
+ ```
258
+
259
+ or try the lib from the console with:
196
260
 
197
- Original author: Duncan Robertson
261
+ ```
262
+ $ ./bin/console
263
+ ```
264
+
265
+ ## Linting
198
266
 
199
- Special thanks to the following people for submitting patches:
267
+ The project uses [standardrb](https://github.com/testdouble/standard) and can be used with:
200
268
 
201
- * [Andy Brody](https://github.com/ab)
202
- * [Chris Mowforth](http://blog.99th.st)
203
- * [Daniel Schierbeck](https://github.com/dasch)
204
- * [Gioele Barabucci](https://github.com/gioele)
205
- * [Ken Collins](https://github.com/metaskills)
206
- * [Rob la Lau](https://github.com/ohreally)
207
- * [Tore Darell](http://tore.darell.no)
208
- * Vladislav Gorodetskiy
269
+ ```
270
+ $ bundle install
271
+ $ rake standard # checks
272
+ $ rake standard:fix # fixes
273
+ ```
209
274
 
210
275
  ## Contributing
276
+
277
+ I am not currently accepting any new renderers as the current `as_png`, `as_svg` and `as_ansi` work for most cases. If you need something different from what's available, the [`rqrcode_core`](https://github.com/whomwah/rqrcode_core) gem gives you access to all the QR Code information you will need so makes it simple to generate your own.
278
+
279
+ The motivation for the above is because the rendering side of this gem takes up the most time. It seems that many people want a slightly different version of a QR Code so supporting all the variations would be hard. The easiest way is to empower people to create their own versions which they can manage and share. This is what `rqrcode_core` does.
280
+
281
+ Any contribution PR's will be greatly accepted. It's important that they are well tested and backwards compatible.
282
+
211
283
  * Fork the project
212
284
  * Send a pull request
213
285
  * Don't touch the .gemspec, I'll do that when I release a new version
214
286
 
287
+ Thanks D.
288
+
289
+ ## Authors
290
+
291
+ Original RQRCode author: Duncan Robertson
292
+
293
+ A massive thanks to [all the contributors of the library over the years](https://github.com/whomwah/rqrcode/graphs/contributors). It wouldn't exist if it wasn't for you all.
294
+
295
+ Oh, and thanks to my bosses at https://kyan.com for giving me time to maintain this project.
296
+
297
+ ## Resources
298
+
299
+ * wikipedia:: http://en.wikipedia.org/wiki/QR_Code
300
+ * Denso-Wave website:: http://www.denso-wave.com/qrcode/index-e.html
301
+ * kaywa:: http://qrcode.kaywa.com
302
+
215
303
  ## Copyright
216
304
 
217
305
  MIT License (http://www.opensource.org/licenses/mit-license.html)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ begin
2
+ require "standard/rake"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: [:spec, "standard:fix"]
8
+ rescue LoadError
9
+ # no standard/rspec available
10
+ end
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-slate