neonichu-asciiart 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +186 -0
- data/Rakefile +1 -0
- data/asciiart.gemspec +24 -0
- data/bin/asciiart +57 -0
- data/lib/asciiart.rb +97 -0
- data/lib/asciiart/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce65f1d28396fdb291d4041171539ecb7b653092
|
4
|
+
data.tar.gz: 6e845b422efe65feb0b53dc03a27bd1582d17c62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f13744ecf3a29e26c06b5c8de930d98c4992b63d736f1e5f3bcdf53693f1c2c9dddcc64327139c29b495a5636074a3839c0ef57c94a481ecca672c154157c40a
|
7
|
+
data.tar.gz: ce27c2cc419f4eb3d63f390081ce049a77fe4da6df3fed22ce32179fbb153431191f475ddd53afba7934ec267edec949d8ed6a7ee0c8ef7dc5ef7321011eab0e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Eastmedia
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
## This is a fork of [asciiart](https://github.com/nodanaonlyzuul/asciiart) because the original project is inactive. All the credit belongs to them, though, this only contains minor compatibility fixes.
|
2
|
+
|
3
|
+
# Developed At:
|
4
|
+
|
5
|
+
+----------------------------------------------------------------------------------------------------+
|
6
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
7
|
+
|oo: ~oooo~ +oooo+:~ :o~ ~ :+ ~oooo+ ~o+ o+ ~+ooo~ ~oooo: :oooooo|
|
8
|
+
|oo: +oooooooo: : +ooo ~+oo+:+oooo: +ooo+ :oo+ ~o+ +oooooo+ +oo++~ +o~ :ooo+ : :ooooo|
|
9
|
+
|oo: ~ ~~ :oo+ +o: ooo+ ~~+ooooo: +ooo+ +~ +o +~ ~o+ ~ ~ ~o+ +ooooo ~o~ ~oo+ :o+ +oooo|
|
10
|
+
|oo: +++++oo+ ::: ~ooooo+++~ +ooo+ oooo+ +o +o ~o+ ++++++o+ +oooo+ :o :oo ::: oooo|
|
11
|
+
|oo: ::::::+ ~::~~: ~o ~:::~ oooo: +ooo+ +o+ :oo ~o+ ~:::::o+ ~::~ +oo ~o :~:~: ooo|
|
12
|
+
|oo+::::::::+::oooooo+::oo+:::~:+ooooo+::ooooo::ooo++ooo+:+oo::::::::oo::::::++oooo+:+o::+oooooo::+oo|
|
13
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
14
|
+
+----------------------------------------------------------------------------------------------------+
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'asciiart'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install asciiart
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
### In Code
|
33
|
+
|
34
|
+
require 'asciiart'
|
35
|
+
a = AsciiArt.new("/Users/sschor/Desktop/uncle_larry.jpg")
|
36
|
+
=> #<AsciiArt:0x00000100878678 @file=#<File:/Users/sschor/Desktop/uncle_larry.jpg>>
|
37
|
+
puts a.to_ascii_art
|
38
|
+
=> ...untold glory follows
|
39
|
+
|
40
|
+
_or_
|
41
|
+
|
42
|
+
require 'asciiart'
|
43
|
+
a = AsciiArt.new("https://f.cloud.github.com/assets/54012/36827/2081922c-5377-11e2-9e39-3fafca0cdb79.png")
|
44
|
+
=> #<AsciiArt:0x007fa889cbacf8 @data="...">
|
45
|
+
puts a.to_ascii_art
|
46
|
+
+----------------------------------------------------------------------------------------------------+
|
47
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
48
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
49
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
50
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
51
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
52
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
53
|
+
|ooooooooooooooooooooooooooooooooooooooo++oo+++++++o+o+oooooooooooooooooooooooooooooooooooooooooooooo|
|
54
|
+
|ooooooooooooooooooooooooooooooooo++++++++::::::::::+:+++++++oooooooooooooooooooooooooooooooooooooooo|
|
55
|
+
|oooooooooooooooooooooooooooo+++::~~~......... . ........~~~::+++oooooooooooooooooooooooooooooooooooo|
|
56
|
+
|ooooooooooooooooooooooooo++++:~~. .~~:++++ooooooooooooooooooooooooooooooooo|
|
57
|
+
|ooooooooooooooooooooooo++:~~. ....~~~~~~~~~~~.... .~~:+++oooooooooooooooooooooooooooooo|
|
58
|
+
|oooooooooooooooooooo+++:~ .~~:::+++++o+++++++::~~.. .~:++ooooooooooooooooooooooooooooo|
|
59
|
+
|oooooooooooooooooo++::~. .~~:::+++o+oooooooooo+++++:::~~.. .~::++oooooooooooooooooooooooooo|
|
60
|
+
|ooooooooooooooooo++:~. .~+++oooooooooooooooooooooooooo++:~. .~:++ooooooooooooooooooooooooo|
|
61
|
+
|ooooooooooooooo++:~.. .~~:+++oooooooooooooooooooooooooo+++:~~. ..~:+oooooooooooooooooooooooo|
|
62
|
+
|ooooooooooooooo+:~. .~:+++::+++++ooooooo+ooooooooooo++++::++::~. ..:++oooooooooooooooooooooo|
|
63
|
+
|ooooooooooooo+++~. .~::+++:~~~~~~:::::::::~~~::::::::~~.~.~::++:~~. ~:+oooooooooooooooooooooo|
|
64
|
+
|ooooooooooo+++:~. ~::++++:. ... ... .~~::++::~. .~:++oooooooooooooooooooo|
|
65
|
+
|oooooooooooo+:~.. ..:++o+++:. .~:+++++:. ..~:++ooooooooooooooooooo|
|
66
|
+
|ooooooooooo+::.. ..:++ooo+:~. .~:+ooo++~~. ...~:+ooooooooooooooooooo|
|
67
|
+
|ooooooooooo+:~. ...~:+ooo++:~. ..~:++oo+:~.. ..:+ooooooooooooooooooo|
|
68
|
+
|oooooooooo++~. . .~:++o++:~~. ..~++o++:~.. .:+ooooooooooooooooooo|
|
69
|
+
|ooooooooooo:~. .~::+oo++~~ ~:+o+++:. .~++oooooooooooooooooo|
|
70
|
+
|oooooooooo++:. .~::++o+:~. .~++oo++:~. .:+o+ooooooooooooooooo|
|
71
|
+
|ooooooooooo:~. ...::+oo+:~. ~:+oo++:~. .:+++ooooooooooooooooo|
|
72
|
+
|oooooooooo++:. .~:+++o+:~ .~++o++:~~ .~+ooooooooooooooooooo|
|
73
|
+
|ooooooooooo+~. .~~:+ooo+~. .~:+o+++~~. .~+ooooooooooooooooooo|
|
74
|
+
|ooooooooooo:~.. .~:+++++~~. .~+o+o+:~. .:++oooooooooooooooooo|
|
75
|
+
|ooooooooooo+~.. ..~:++o+::.. .~:+oo++:~. ~:+ooooooooooooooooooo|
|
76
|
+
|ooooooooooo++~... .~++oo+::~. ~~++o++:~. ..~:+ooooooooooooooooooo|
|
77
|
+
|ooooooooooo++:~. .:+++o++:~. ..~:+++oo+~. ..~:+oooooooooooooooooooo|
|
78
|
+
|oooooooooooo++::. ..~:++oo++::~~~. ...~~::+++o++:~~ ..~:+++ooooooooooooooooooo|
|
79
|
+
|ooooooooooooo+++~. ..::+oo+o++++:~. .~::+++oo++++:~. .:++o+oooooooooooooooooooo|
|
80
|
+
|ooooooooooooooo+:~. .~:++ooooo++:~. .~:+o+oooo++:~.. .~:++oooooooooooooooooooooo|
|
81
|
+
|ooooooooooooooo++::~. .~~:++ooooo+:. .:++oooo++:~~. ..~:+oooooooooooooooooooooooo|
|
82
|
+
|ooooooooooooooooo++::. .~~::+++:~. .~++o+::~~.. .~:++ooooooooooooooooooooooooo|
|
83
|
+
|ooooooooooooooooooo++:.. .~::::~. .~:::~~.. .~:++ooooooooooooooooooooooooooo|
|
84
|
+
|oooooooooooooooooooo+++:~~.. .... .... ..~~:++oooooooooooooooooooooooooooo|
|
85
|
+
|ooooooooooooooooooooooo+++:~~. ..~:++oooooooooooooooooooooooooooooooo|
|
86
|
+
|ooooooooooooooooooooooooo+++:~~~.... ...~~::++++oooooooooooooooooooooooooooooooo|
|
87
|
+
|ooooooooooooooooooooooooooooo+++++::~~.... . .....~~:::+++oooooooooooooooooooooooooooooooooooooo|
|
88
|
+
|ooooooooooooooooooooooooooooooooo+++++::::~:~:~::~:::::++++ooooooooooooooooooooooooooooooooooooooooo|
|
89
|
+
|ooooooooooooooooooooooooooooooooooooo+oo+oo+o++o+oo+oooooooooooooooooooooooooooooooooooooooooooooooo|
|
90
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
91
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
92
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
93
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
94
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
95
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
96
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
|
97
|
+
+----------------------------------------------------------------------------------------------------+
|
98
|
+
=> nil
|
99
|
+
|
100
|
+
_or make it thinner_
|
101
|
+
|
102
|
+
require 'asciiart'
|
103
|
+
a = AsciiArt.new("https://f.cloud.github.com/assets/54012/36827/2081922c-5377-11e2-9e39-3fafca0cdb79.png")
|
104
|
+
=> #<AsciiArt:0x007fa889cbacf8 @data="...">
|
105
|
+
|
106
|
+
|
107
|
+
print a.to_ascii_art(width: 50)
|
108
|
+
+--------------------------------------------------+
|
109
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
110
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
111
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
112
|
+
|oooooooooooooooooo===++++====ooooooooooooooooooooo|
|
113
|
+
|ooooooooooooo=+:~.~........~~~:+=ooooooooooooooooo|
|
114
|
+
|oooooooooo==:~...~~:++++++:~~..~~:+=oooooooooooooo|
|
115
|
+
|oooooooo=+:...~++====oooo====+:~..~:+=oooooooooooo|
|
116
|
+
|ooooooo=+~..~:++==ooooooooooo=++:~..~+=ooooooooooo|
|
117
|
+
|oooooo=+~.~:+=+~.~~~~~~~~:~~~.~:++:~.~+=oooooooooo|
|
118
|
+
|ooooo=+~~.+===~................~+==:.~~+=ooooooooo|
|
119
|
+
|ooooo=:~~:+=+:~................~~+=+:~.:=ooooooooo|
|
120
|
+
|ooooo=~.~+==+~...................+==+~.:=ooooooooo|
|
121
|
+
|ooooo=~~~+==:~...................:==+~.:=ooooooooo|
|
122
|
+
|ooooo=~~~:==+~..................~+==+~.~=ooooooooo|
|
123
|
+
|ooooo=:~~~+=++~.................:+=+~~~:=ooooooooo|
|
124
|
+
|ooooo=+:..~+==+~~...........~~~+==+~..:+=ooooooooo|
|
125
|
+
|ooooooo+:..~:+=o=+:........:+====:~.~:==oooooooooo|
|
126
|
+
|oooooooo=+~.~~:+==+~......~+==+:~..~:+oooooooooooo|
|
127
|
+
|ooooooooo=+:~..~~:~~.......~:~~..~:+oooooooooooooo|
|
128
|
+
|oooooooooooo=+~~..............~:+=oooooooooooooooo|
|
129
|
+
|ooooooooooooooo==++:~~~~~~:++==ooooooooooooooooooo|
|
130
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
131
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
132
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
133
|
+
|oooooooooooooooooooooooooooooooooooooooooooooooooo|
|
134
|
+
+--------------------------------------------------+
|
135
|
+
|
136
|
+
Add color with the "color" option
|
137
|
+
|
138
|
+
require 'asciiart'
|
139
|
+
a = AsciiArt.new("http://www.evangogh.org/images/paintings/self-portrait.jpg")
|
140
|
+
=> #<AsciiArt:0x007fa889cbacf8 @data="...">
|
141
|
+
|
142
|
+
puts a.to_ascii_art(color: true) =>
|
143
|
+
|
144
|
+
[Booyah!](http://farm9.staticflickr.com/8080/8424360420_8011af48fe_b.jpg)
|
145
|
+
|
146
|
+
### In The Command Line
|
147
|
+
|
148
|
+
Local Files
|
149
|
+
|
150
|
+
$ asciiart ~/Desktop/uncle_larry.jpg
|
151
|
+
|
152
|
+
Remote Images
|
153
|
+
|
154
|
+
$ asciiart http://www.google.com/images/srpr/logo3w.png
|
155
|
+
|
156
|
+
Output it as HTML
|
157
|
+
|
158
|
+
$ asciiart -c -f html ~/Ross/cppsource/secret/noopen/sillhere?/turnback/bea-arthur-birthdaysuit.jpg > ~/Desktop/ascii-as-html.html
|
159
|
+
|
160
|
+
_or smaller_
|
161
|
+
|
162
|
+
$ asciiart -w 50 -c -f html ~/Stephen/boringSQLsnippets/nothingtoseehere/turnback/bea-arthur-with-ross's-head.jpg > ~/Desktop/saturdaynight.html
|
163
|
+
|
164
|
+
Get Help
|
165
|
+
|
166
|
+
$ asciiart -h
|
167
|
+
|
168
|
+
Usage: asciiart [options] <path_or_url>
|
169
|
+
-w, --width WIDTH Width of the finished Ascii Art (Default: 100)
|
170
|
+
-f, --format [text/html] output format (Default: text)
|
171
|
+
-c, --color Switch to use colored terminal output (Default: false)
|
172
|
+
-i, --invert-chars Invert the character map. *Depending on background and image color - this can make the result clearer.*
|
173
|
+
-v, --version Show AsciiArt version
|
174
|
+
-h, --help Show this message
|
175
|
+
|
176
|
+
## Requirements
|
177
|
+
|
178
|
+
This app requires Ruby 1.9
|
179
|
+
|
180
|
+
## Contributing
|
181
|
+
|
182
|
+
1. Fork it
|
183
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
184
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
185
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
186
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/asciiart.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'asciiart/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "neonichu-asciiart"
|
8
|
+
gem.version = AsciiArt::VERSION
|
9
|
+
gem.authors = ["nodanaonlyzuul", "rosscooperman"]
|
10
|
+
gem.email = ["stephen@eastmedia.com"]
|
11
|
+
# gem.description = %q{A command line tool to turn images into ASCII art}
|
12
|
+
gem.summary = %q{A command line tool to turn images into ASCII art}
|
13
|
+
gem.homepage = "https://github.com/neonichu/asciiart"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency('rmagick', '~> 2.15.0')
|
21
|
+
gem.add_dependency('rainbow', '~> 2.1.0')
|
22
|
+
|
23
|
+
gem.add_development_dependency('pry')
|
24
|
+
end
|
data/bin/asciiart
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'asciiart'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
invert_chars = false
|
8
|
+
|
9
|
+
opt_parser = OptionParser.new do |opts|
|
10
|
+
opts.banner = 'Usage: asciiart [options] <path_or_url>'
|
11
|
+
|
12
|
+
opts.on('-w', '--width WIDTH', 'Width of the finished Ascii Art (Default: 100)') do |width|
|
13
|
+
options[:width] = width.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on('-f', '--format [text/html]', 'output format (Default: text)') do |format|
|
17
|
+
options[:format] = format
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-c', '--color', 'Switch to use colored terminal output (Default: false)') do
|
21
|
+
options[:color] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-i', '--invert-chars', 'Invert the character map. Depending on your terminal and image this can make the image clearer (or a lot worse)') do
|
25
|
+
invert_chars = true
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on_tail('-v', '--version', 'Show AsciiArt version') do
|
29
|
+
puts 'AsciiArt version ' + AsciiArt::VERSION
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
34
|
+
puts opts
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
opt_parser.parse!
|
42
|
+
rescue OptionParser::MissingArgument => e
|
43
|
+
puts "ERROR: #{e.message.capitalize}\n#{opt_parser}"
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
|
47
|
+
if ARGV.length == 0
|
48
|
+
puts "ERROR: You must specify a path or URL to convert\n#{opt_parser}"
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
art = AsciiArt.new(ARGV[0])
|
53
|
+
|
54
|
+
art.image_chars = art.image_chars.reverse if invert_chars
|
55
|
+
|
56
|
+
puts art.to_ascii_art(options)
|
57
|
+
|
data/lib/asciiart.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "asciiart/version"
|
2
|
+
require 'RMagick'
|
3
|
+
require 'uri'
|
4
|
+
require 'open-uri'
|
5
|
+
require 'rainbow'
|
6
|
+
|
7
|
+
class AsciiArt
|
8
|
+
|
9
|
+
attr_writer :image_chars
|
10
|
+
|
11
|
+
def initialize(path_to_file)
|
12
|
+
# open-uri open will fallback to IO open
|
13
|
+
open(path_to_file) { |file| @data = file.read }
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_ascii_art(options = {})
|
18
|
+
options = { width: 100, color: false, format: "text" }.merge(options)
|
19
|
+
|
20
|
+
img = Magick::Image.from_blob(@data).first
|
21
|
+
|
22
|
+
width = options[:width]
|
23
|
+
scale = (width.to_f / img.columns)
|
24
|
+
height = ((img.rows * scale) / 2).to_i
|
25
|
+
|
26
|
+
img.resize!(width, height)
|
27
|
+
color_image = img.dup if options[:color]
|
28
|
+
img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
|
29
|
+
quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
|
30
|
+
image_chars.map! {|char| char == " " ? " " : char } if options[:format] == "html"
|
31
|
+
|
32
|
+
border = "+#{'-' * width}+#{line_break(options[:format])}"
|
33
|
+
border = html_char(border) if options[:format] == "html"
|
34
|
+
|
35
|
+
output = border.dup
|
36
|
+
|
37
|
+
img.view(0, 0, width, height) do |view|
|
38
|
+
height.times do |i|
|
39
|
+
output << '|'
|
40
|
+
width.times do |j|
|
41
|
+
|
42
|
+
character = image_chars[view[i][j].red/quantum_calc]
|
43
|
+
|
44
|
+
if options[:format] == "html"
|
45
|
+
if (options[:color])
|
46
|
+
|
47
|
+
pix = color_image.pixel_color(j,i)
|
48
|
+
color_string = "color: #{pix.to_color( Magick::AllCompliance,false,8, true)};"
|
49
|
+
else
|
50
|
+
color_string = ""
|
51
|
+
end
|
52
|
+
character = html_char(character, color_string)
|
53
|
+
else
|
54
|
+
# text-format
|
55
|
+
if options[:color]
|
56
|
+
pix = color_image.pixel_color(j,i)
|
57
|
+
character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
output << character
|
62
|
+
end
|
63
|
+
|
64
|
+
output << "|#{line_break(options[:format])}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
output + border
|
69
|
+
end
|
70
|
+
|
71
|
+
def image_chars
|
72
|
+
@image_chars ||= ' .~:+=o*x^%#@$MW'.chars.to_a
|
73
|
+
end
|
74
|
+
|
75
|
+
def inspect
|
76
|
+
"#<#{self.class.to_s}>"
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def line_break(format)
|
82
|
+
(format == "text") ? "\n" : "<br/>"
|
83
|
+
end
|
84
|
+
|
85
|
+
def unified_rgb_value(number)
|
86
|
+
if defined?(Magick::QuantumDepth)
|
87
|
+
return (Magick::QuantumDepth == 16) ? (number / 256) : number
|
88
|
+
else
|
89
|
+
return (Magick::QuantumRange == 65535) ? (number / 256) : number
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def html_char(char, additional_style = "")
|
94
|
+
"<span style=\"font-family: 'Lucida Console', Monaco, monospace; #{additional_style}\">#{char}</span>"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: neonichu-asciiart
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nodanaonlyzuul
|
8
|
+
- rosscooperman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rmagick
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.15.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.15.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rainbow
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.1.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.1.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- stephen@eastmedia.com
|
59
|
+
executables:
|
60
|
+
- asciiart
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- asciiart.gemspec
|
70
|
+
- bin/asciiart
|
71
|
+
- lib/asciiart.rb
|
72
|
+
- lib/asciiart/version.rb
|
73
|
+
homepage: https://github.com/neonichu/asciiart
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: A command line tool to turn images into ASCII art
|
96
|
+
test_files: []
|
97
|
+
has_rdoc:
|