slascii 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b18a12f2cde70d9ded4d078cef3213553386df95
4
+ data.tar.gz: 974e244b2cfc282fd0055b8b8a135a21c29d55a4
5
+ SHA512:
6
+ metadata.gz: 8841f2df4da06e059093f38445d923ad7cbb5e2956a3e67967459db9ee21825c030bdb830d0c1d7a00c7dbcfa741137f5e2baf0953e7e252fffabab0cc20d015
7
+ data.tar.gz: 13300d3259684b506ec67f604c573a2b3a3aa3c7649337061cb983e8f7c96315f0a3842757e8cdc65fd4b030b4d80bc81ec8c13e7cac6e5723e92fd4569102bc
@@ -0,0 +1 @@
1
+ 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ # Specify your gem's dependencies in slascii.gemspec
5
+ gemspec
6
+
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ slascii (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.1)
10
+ method_source (0.8.2)
11
+ mini_magick (4.7.0)
12
+ pry (0.10.4)
13
+ coderay (~> 1.1.0)
14
+ method_source (~> 0.8.1)
15
+ slop (~> 3.4)
16
+ rake (10.4.2)
17
+ slop (3.6.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.15)
24
+ mini_magick (~> 4.7)
25
+ pry (~> 0.1)
26
+ rake (~> 10.0)
27
+ slascii!
28
+
29
+ BUNDLED WITH
30
+ 1.15.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Matthew Eagar
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.
@@ -0,0 +1,223 @@
1
+ # Slascii
2
+
3
+ ## About
4
+
5
+ Slascii is a **Sl**ack **Ascii**-art generator. It takes pictures, and renders them as text, using a variety of options.
6
+
7
+ It's only Slack-specific in that it will (by default) output ASCII art that is under 4000 characters in length, which is the character limit of a Slack message.
8
+
9
+ ## Usage
10
+
11
+ Install it:
12
+
13
+ ```bash
14
+ $ gem install slascii
15
+ ```
16
+
17
+ Run it:
18
+
19
+ ```text
20
+ $ slascii face.png --width 30
21
+
22
+
23
+ --++oo330000000033oo++--
24
+ --oo333333oo++++++++oo333333oo--
25
+ ++3333oo--------------------oo3333++
26
+ oo00oo----------------------------oo00oo
27
+ oo33++--------------------------------++33oo
28
+ oo33++------------------------------------++33oo
29
+ ++00++--++------------------------++----------++00++
30
+ --33oooo33oo33oo----------------oo33oooo33++------oo33--
31
+ oo33oooo-- 3300oo------------oooo-- ++0033++------33oo
32
+ --33oooo-- --000000++--------++oo oo0000oo------oo33--
33
+ ++33++oo oo33oooo--------oo-- ++33oo33--------33++
34
+ oo33++oo --oo--------oo-- oo++------33oo
35
+ 33oo++oo --oo--------oo-- oo++------oo33
36
+ 00++--33oooooooooo33oo--------oo33oooooooooooo33--------++00
37
+ 00++----------------------------------------------------++00
38
+ 00++----------------------------------------------------++00
39
+ 00++----oooooooooooooooooooooooooooooooooooooo++--------++00
40
+ 33oo----oo00333333333333333333333333333333330033--------oo33
41
+ oo33----++33333333333333333333333333333333333333--------33oo
42
+ ++33------33333333333333333333333333333333333333--------33++
43
+ --33oo----oo333333333333333333333333333333333333------oo33--
44
+ oo33------3333333333333333333333333333333333oo------33++
45
+ --33oo----oo00333333333333++------++oo333333++----oo33--
46
+ ++00++----333333333333++------------oo00oo----++00++
47
+ oo33++----33333333++------------++33oo----++33oo
48
+ oo33++----330033----------++oo33oo----++33oo
49
+ oo00oo----++3333oooooo3333oo------oo00oo
50
+ ++3333oo------++++++--------oo3333++
51
+ --oo333333oo++++++++oo333333++--
52
+ --++oo330000000033oo++--
53
+ ```
54
+
55
+ ## A note about palettes
56
+
57
+ Some palettes won't make sense for you, because your team won't have our custom emoji. Some palettes output emoji in
58
+ the form `:troll:` and only align properly in a mono-space font (use triple backticks).
59
+
60
+ ## Samples
61
+
62
+ ![troll](https://github.com/meagar/slascii/blob/master/samples/troll.png?raw=true)
63
+
64
+ ```text
65
+ ----++oooo33333333333333333333333333333333oo333333++
66
+ --oo3333333333oooooo++++++++++++++++++++------------++oo33++
67
+ --++33oooo++++++------------------------------------ --33oo
68
+ ++33oo------++--------------++++----------------------++-- --33++
69
+ --oo33-- -- ---------------- ------------++++------ ++33--
70
+ oo33-- ------------++-- -- --------++++------ --33++
71
+ oo-- --++ ---- ---- ------------ ++33
72
+ --33 -- ---- -- ------ ------ --33++
73
+ oooo -- ++oo3333333333oo-- ++33--
74
+ ++33++ ++oo3333oo++---- --oo33++--330000003333-- --33oo
75
+ ++33++----------++00333300000033-- 33oo----++33000000333333--++++ --++oo33oo--
76
+ --33oo++++-- --++++oooo3333003333++ --33oooo3333++++++--++oooo--------++++------++oooo--
77
+ 3333++++------ --++33++ --33oo-- --33-- --oo3333oo33oo-- --++oo--
78
+ 00oo------oo3333oo-- --oo oo33oo++++oo3333++---- ++33-- --oooo
79
+ 00oo------++----oo00oo33++ oo33 --++++++++-- 33-- oooo --++33
80
+ 33oo---- oo--++oo++ --oo33++ --++++-- --++330033-- --33------33
81
+ oo33------ --33-- --3333-- --oo33oo-------- --oo3333++++0033++++33------33
82
+ --33++---- oo00-- --oo00oo --oooooo--++oo --++oo3333++ oo33++++oooo----++33
83
+ oooo--++--3300oo-- --------oooo --oo++oo++33++ --oo33333333-- ++00++ ++--++--33oo
84
+ --33-- ++00330033++ oo33oo-- --++++oo3333oo++----33----oo0033-- ------oo33--
85
+ 33++ ++0033oo333333++---- --oo++------++oo33333333-- --oo0033333300++ --oo33--
86
+ ++oo ++00oo++oo--3333333333333333333333oooo++--++33 --++330000oo--oooo oo33--
87
+ ++33 ++00oo33oo 33++ --++33++----++oo --33oo330000333333 ++33-- ++33--
88
+ --33 ++00000033oo33oo------33------oooo------++oo00000033++--++33++33++ 33++
89
+ --33 ++0000000000000000333300333333000033330000003333-- --3300++ ++33
90
+ --33 --00000000000000000000000000000000000033oo--++oo ++33oo oo++
91
+ --oo --33330033000000000000000033333333oo-- --33-- --oo33++ ++33--
92
+ ++oo oo3333++33++oo33----33oo---- ++oo oooo++3333-- ++33++
93
+ ++oo --3333++oooo--33++ ++33 ++oo --oo0033++ -- ---- ++33++
94
+ oo++ ++33333333++33oo----33-- ++33++++oo333333++----++----++++--oo33++
95
+ oo++ --++oo3333333333330033333333333333oooo-- --++++--++++--++33oo--
96
+ 33++ -- -- ----++++++++++++------ --++++++++++--++3333++
97
+ 33-- -- --++-- ------------ ----++++++++----++3333++
98
+ 33-- ---- --++++---- ------++++++++------++3333++
99
+ 33-- --++------ ---------------- ++33oo++
100
+ 33++ ---------------------- ++33oo++
101
+ ++33-- --++++++33oo++
102
+ ++33++ --++33330033oo++
103
+ ++3333oo++--------++++oooo3333oo++++--
104
+ --++3333000000333333oo++----
105
+ ```
106
+
107
+ ---
108
+
109
+ ![bob](https://github.com/meagar/slascii/blob/master/samples/bob.png?raw=true)
110
+
111
+ ```text
112
+ --++--++++----------------
113
+ ++oo33333333333333333333333333oo++--
114
+ --oo330033333333oo33333333oo3333oooo3333++
115
+ ++333333333333oooo++++++33oooo++oo++++oo3333oo
116
+ ++33333333++oooo++++oo----oooo++++++oo++oooooo33++++--
117
+ --333333oooooo++oooo++oo++----oo--++++oooooooooo33oo++
118
+ oo003333333333333333oo++oo----oo++++++3333oooooo333333++
119
+ ++0000003333000000000033oo33++++oooooooo333333333333330033--
120
+ 330000000033333300000000333333oo3333oo333333333333oo33000033
121
+ --3333003333oooo3333330000330033333333oo333333oo++--++33003333++
122
+ ++33333333oooo++oooooo3333330000330033oooo++----------oo00oo33oo
123
+ oo333333oo++++++++++++++++++oo3333oo++----------------++00oo33oo
124
+ oo330033oo++------------------++------------------------33oooo33
125
+ oo330033oo++--------------------------------------------oooooo33
126
+ 33000033oo++--------------------------------------------oo33oo33
127
+ 33000033oo++--------------------------------------------oo33oo33
128
+ 33000033oo++----------------------------------------++--oo33oo33
129
+ 33000033oo++----------------------------------------++--oo333333
130
+ oo000033oo++----------------------------------------++--oo333333
131
+ ++000033oo++----------------------------------------++--oo33oo33
132
+ oo330033oo++oo33333333++----------------oo3333oooo++++--oo003333--
133
+ oooo3333oooo++++++oo3333++------------++33oooo++++oooo++++0033oo--
134
+ oooooooooooo++++++++oo33oo++--------++oooo++++------oo++++3333++
135
+ oo33oooo++++oooooooooo3333oo++----++3333oooooooooo--++++--3333oo
136
+ oo33oo++--++oo--oooo++++3333++----oooooo--oooo++oo++--++--3333++
137
+ oo33oo++--------++++--++oooo++------------++++--++----++--3333++
138
+ ++33oo++----------++++++++oo++----------++++--------------oo33--
139
+ ++33oo++------++++++++----oo++------------++++---- ------oooo--
140
+ --oooo++------------------oo-------------------- ------++oo
141
+ --++oo++----------------++++-------------------- --------++++--
142
+ ++oo++++---- -- ----++++------------------ --------++--
143
+ --++--oo---- --++++++++------++--++++-- --------------
144
+ ----oo++-- --++++++oo++------++++++++oo-- ----++++--
145
+ --oooo++--++++++3333oo++++oo33++----oooo--++++oo++--
146
+ ++oo33oooo++++33333333333333++------++oooooooooo++--
147
+ ++oo3333++++oo333333333333++------++++oooooo++oo++--
148
+ --oooooo--++330033333333++--++oooo3300oo++--++oo++
149
+ --oo++oo++--oo33++----++----------33oo++----++oo++
150
+ ++oooo++--oo3333oo-- --------++oo--------oooo--
151
+ --oo++++--++333300oo------++++++++--------oo++
152
+ oo++++----330033oooo++++++++----------++oo--
153
+ ++++++--oo000033oo++------------------oooo
154
+ --++++oo0000oo3333oooooooo++++--------33++
155
+ --oo0000oo++3333oooo++++++--------oooo
156
+ ---------- ++333333++oo33++------------------33++
157
+ --++33oo--oo----333333oo++oooo------------------oooo
158
+ ----3333--oo00oo333333oooooooooo----------------++oo--
159
+ ----++--++3300003333oo--oooooooo++++----------oooo--
160
+ ++3333oo--oo000033oo-- --oo3333oooooooooooooo33--
161
+ --330033++++000000++ --++++++oooo33oooo--
162
+ oo0000oo++3300oo
163
+ --0000oo++33oo
164
+ ++000033oo--
165
+ --++++
166
+ ```
167
+
168
+ ---
169
+
170
+ ![bob](https://github.com/meagar/slascii/blob/master/samples/einstein.jpg?raw=true)
171
+
172
+
173
+ ```text
174
+ 333333333333333333333333333333333333333333333333333333333333333333333333333333
175
+ 333333333333333333333333333333333333333333333333333333333333333333333333333333
176
+ 333333333333333333333333333333333333333333333333333333333333333333333333333333
177
+ 333333333333333333333333333333333333333333333333333333333333333333333333333333
178
+ 333333333333333333333333333333333333333333333333333333333333333333333333333333
179
+ 333333333333333333333333333333333333333333333333333333333333333333333333333333
180
+ 3333333333333333333333333333333333333333333333oo333333333333333333333333000033
181
+ 3333333333333333333333333333333333333333oooooooooooo33333333333333330000000033
182
+ 33333333333333333333333333333333333333oo++oooooooooooooo33333333330000000000oo
183
+ 3333333333333333333333333333333333oooooo++++++++++++++oo33333333000000000000++
184
+ oo3333333333333333333333333333oooo++oo++++++++++++++++oooooo3300000000000000++
185
+ 333333333333333333333333333333oo++++++++++++++++++++++++++oo333300000000000033
186
+ 3333oooooo3333333333333333oooooo++--------------++++++++++++oo3300000000000000
187
+ oooooooooo33333333333333oooooo++--------------------++++++++oooo00000000000000
188
+ oooooooooo333333333333oooooo------ --------++++++++oo33000000000000
189
+ oooooooo333333333333oooo33++-- ----------++++--++33000000000000
190
+ oooooooo33333333oooooo33oo++-- ----------++++--++33000000000000
191
+ oooooo3333333333333333333333oo-- --++++----------------++oo000000000000
192
+ ++oooooo3333333333oooooo33oo++-- ----------------------++oo330000000000
193
+ ++oooooo3333333333oo33oo++--++++-- ----------------------++oo333300000000
194
+ ++oooo333333000033333333++oooo++++-- ----++++++----------------++oooo33000000
195
+ oooo33333300000033333333oooooooo++-- --++++33oo----------------++oooo33000000
196
+ oooo33330000000033333333oooooo++oo------++++oo++--------------++++oooo33330000
197
+ oo3333330000000033000033oo++++++oo----------------------++++++oooooooooo330000
198
+ 3300000000000000000000oo------++++--++-- ------++++++++++++oooo++oo330000
199
+ 3300000000000000000000oo------++----++++-- --++++oooo----++++--++oo3300
200
+ 3300000000000000000000oo----++oo-- ------ --++++oo++------++--++++3300
201
+ 330000000000000000330033++--++oo++++-------- ----++++oo++--++------++oo3300
202
+ 330033000000000000000033++--------------------------++++oo--++++++++--++oo3300
203
+ 330000000000000000000033oo++------------------------++++++++oooooo++++oo330000
204
+ 000000000000000000000033oooooooo++++++++++++--------++++oo33000033333300000000
205
+ 000000000000000000000033oo--oo33oooo++++33oo--------++++3300000000000000000033
206
+ 000000000000000000000000oo----++++++++++oo++--------++330000000000000000000033
207
+ 00000000000000000000000033++--++--++++oo++--------++oo000000000000000000003333
208
+ 00000000000000000000000000oo--oo--++++oo----------3300000000000000000000333333
209
+ 0000003333333300000000000033oooo++++++---- --++330000000000000000000033333333
210
+ 003333333333330000000000000033oooo++-- ++33000000000000000000003333333300
211
+ 33333333333333330000000000000033oo++-- --++3300000000000000000000333333333300
212
+ 3333333333333300000033000000000033++++++oo000000000000000000000033333333330033
213
+ 333333333333000000000000000033oooo33330000000000000000000000003333333333000033
214
+ 003333330000000000000000003333oo3333000000000000000000000000333333333333003333
215
+ 333333000000000000000000003333330000000000000000000000000033333333333300003333
216
+ 333333000000000000000033333333000000000000000000000000003333333333333300000000
217
+ 000000000000000000000033330000000000000000000000000000333333333333333300000000
218
+ 000000000000000000003333330000000000000000000000000033333333333333330000000000
219
+ 000000000000000000333300000000000000000000000000003333333333333333000000000000
220
+ 000000000000000000000000000000000000000000000000003333333333333333000000000000
221
+ 000000000000000000000000000000000000000000000000333333333333333300000000000000
222
+ 0000000000000000000000000000000000000000000000333333333333333300000000000000
223
+ ```
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "slascii"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "slascii"
4
+
5
+ cli = Slascii::CLI.new
6
+ cli.run
7
+ cli.write_output
@@ -0,0 +1,5 @@
1
+ require 'slascii/version'
2
+ require 'slascii/cli'
3
+
4
+ module Slascii
5
+ end
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'bundler/setup'
4
+ require 'mini_magick'
5
+ require 'pry'
6
+
7
+ module Slascii
8
+ class CLI
9
+ attr_reader :output
10
+
11
+ # Darker to lighter
12
+ PALETTES = {
13
+ ascii: ['00', '33', 'oo', '++', '--', ' '].freeze,
14
+ unicode: ['██', '▓▓', '▒▒', ' '].freeze,
15
+ shopify: [':s33:', ':s13:', ':s12:', ':s11:', ':s02:', ':s00:'].freeze,
16
+ ping_pong: [':pong:', ':s00:'].freeze,
17
+ troll: [':troll:', ' '].freeze,
18
+ madmatt: [':madmatt:', ':s00:'].freeze,
19
+ }.freeze
20
+
21
+ def run
22
+ ### Program EntryPoint ###
23
+ options = parse_options
24
+
25
+ palette = options[:palette]
26
+ palette = palette.reverse if options[:invert]
27
+
28
+ @output = if options[:chars]
29
+ make_art_to_character_count(options[:filename], palette, options[:chars])
30
+ else
31
+ make_art_to_width(options[:filename], palette, options[:width])
32
+ end
33
+ end
34
+
35
+ def write_output
36
+ puts "#{output}\n\n(#{output.length} chars)"
37
+ end
38
+
39
+ private
40
+
41
+ def verbose?
42
+ @verbose == true
43
+ end
44
+
45
+ def vlog(message)
46
+ puts message if verbose?
47
+ end
48
+
49
+ def parse_options
50
+ options = {}
51
+
52
+ parser = OptionParser.new do |opts|
53
+ opts.banner = "Usage: thumbs.rb [options] FILE_NAME"
54
+
55
+ opts.on('-c', '--chars C', 'Specify the number of characters to use (default 4000, Slack message limit)') do |c|
56
+ options[:chars] = c.to_i
57
+ end
58
+
59
+ opts.on('-w', '--width N', 'Specify width of output (overrides --chars)') do |n|
60
+ options[:width] = n.to_i
61
+ end
62
+
63
+ opts.on '-p', '--palette P', "Specify character palette to use: #{PALETTES.keys.join(', ')}" do |p|
64
+ unless (options[:palette] = PALETTES[p.to_sym])
65
+ puts "Invalid palette: #{p}"
66
+ puts "Available palettes:"
67
+ PALETTES.keys.each { |k| puts " - #{k}" }
68
+ exit
69
+ end
70
+ end
71
+
72
+ opts.on '-i', '--invert', 'Invert colors' do
73
+ options[:invert] = true
74
+ end
75
+
76
+ opts.on '-v', '--verbose', 'Debugging output' do
77
+ @verbose = true
78
+ end
79
+ end
80
+
81
+ parser.parse!
82
+
83
+ options[:filename] = ARGV.pop
84
+
85
+ raise 'Width must be greater than 1' if options[:width] && options[:width] < 1
86
+ raise 'Missing filename' unless options[:filename]
87
+ raise 'Cannot specify both --chars and --width' if options[:chars] && options[:width]
88
+
89
+ options[:chars] = 4000 if options[:chars].nil? && options[:width].nil?
90
+ options[:palette] ||= PALETTES.values.first
91
+
92
+ options
93
+ rescue StandardError => ex
94
+ puts "Error: #{ex.message}\n\n#{parser}"
95
+ exit(1)
96
+ end
97
+
98
+ def open_image(path)
99
+ MiniMagick::Image.open(path)
100
+ rescue StandardError => ex
101
+ puts "Unable to open #{path}: #{ex.message}"
102
+ exit(1)
103
+ end
104
+
105
+ def make_art_to_character_count(path, palette, count)
106
+ vlog "Generating output to #{count} character limit"
107
+
108
+ maps = Hash.new do |hash, width|
109
+ output = make_art_to_width(path, palette, width)
110
+ vlog "Trying #{width}: #{output.length} characters"
111
+ hash[width] = output
112
+ end
113
+
114
+ # Find the lower bound
115
+ lower = 40.downto(1).find do |bound|
116
+ maps[bound].length <= count
117
+ end
118
+
119
+ # Starting from the lower bound, find the first width N that exceeds the character limit, then return map[N - 1]
120
+ lower.upto(Float::INFINITY).find do |n|
121
+ return maps[n] if maps[n + 1].length > count
122
+ end
123
+ end
124
+
125
+ def make_art_to_width(path, palette, width)
126
+ img = open_image(path)
127
+ img.colorspace 'Gray'
128
+
129
+ img.resize "#{width}x10000"
130
+
131
+ # Turn the 2d array of [r, g, b] values into a 2d array of [r] values (r == g == b because grayscale)
132
+ pixels = img.get_pixels.map { |row| row.map(&:first) }
133
+
134
+ # Find the grayscale limits of the photo so we can map only the used range to our palette, which
135
+ # is probably much smaller than the full 255 grayscale values
136
+
137
+ (darkest, lightest) = pixels.flatten.minmax
138
+
139
+ range = lightest - darkest
140
+
141
+ # The gap between each palette value
142
+ step = range.fdiv(palette.size - 1)
143
+
144
+ pixels.map do |row|
145
+ row.map do |pixel|
146
+ palette.fetch(((pixel - darkest) / step).round)
147
+ end.join
148
+ end.join("\n")
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,3 @@
1
+ module Slascii
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slascii/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'slascii'
8
+ spec.version = Slascii::VERSION
9
+ spec.authors = ['Matthew Eagar']
10
+ spec.email = ['meagar@gmail.com']
11
+
12
+ spec.summary = 'Convert images to simple ASCII art for Slack (or elsewhere)'
13
+ spec.description = 'Convert images to simple ASCII art for Slack (or elsewhere)'
14
+ spec.homepage = 'https://github.com/meagar/slascii'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features|samples)/})
27
+ end
28
+
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.15'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'mini_magick', '~> 4.7'
36
+ spec.add_development_dependency 'pry', '~> 0.1'
37
+ end
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.4
5
+ before_install: gem install bundler -v 1.15.0
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in slascii.gemspec
4
+ gemspec
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slascii
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Eagar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mini_magick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ description: Convert images to simple ASCII art for Slack (or elsewhere)
70
+ email:
71
+ - meagar@gmail.com
72
+ executables:
73
+ - slascii
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - exe/slascii
86
+ - lib/slascii.rb
87
+ - lib/slascii/cli.rb
88
+ - lib/slascii/version.rb
89
+ - slascii.gemspec
90
+ - slascii/.gitignore
91
+ - slascii/.travis.yml
92
+ - slascii/Gemfile
93
+ homepage: https://github.com/meagar/slascii
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Convert images to simple ASCII art for Slack (or elsewhere)
118
+ test_files: []