asciiart 0.0.8 → 0.3.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.
- checksums.yaml +5 -13
- data/CHANGELOG.md +41 -0
- data/README.md +2 -2
- data/asciiart.gemspec +3 -3
- data/lib/asciiart/html.rb +56 -0
- data/lib/asciiart/text.rb +56 -0
- data/lib/asciiart/version.rb +1 -1
- data/lib/asciiart.rb +7 -74
- metadata +23 -19
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YjcwNzc4MGM2MTllN2ZlZjg5MmMxNWIwMTI1MDRjODQ2YzA0ZTk4ZA==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73d1db9173b7bb415b28427400d74dc58873a17fb83c35f9680dc9dbfa957a93
|
4
|
+
data.tar.gz: bf4b64962e12bda8dae1b6d856f1bde6f6a6fec86710474dde911a71ab8ad53a
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MDUzNGY5NGE1OWZlMmE2YWVlZjliMzhjMzc3MDk1Y2UwMDBiMGYxZDAzMWRk
|
11
|
-
MjI0Y2IzOTZmNWRmMWQ1NTYxY2VmODM5Mzk4NWRhOGQwNmJiMmY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZTk4NmQ5N2VmODU5OTBjOWQ3ZjNjMGMyMWRhYzcyNzE1MDA3YmRiMWMxODYx
|
14
|
-
YzI1ZGI3NTY2NWNkNWQ0NzIyNDg1NDlmMWJkNTlmYTc5NGY4ZTVjYTYyNjM2
|
15
|
-
MTUzZjNjMTI4ZWQwMzIwYjc1MzhhZjk1MjM4NDA3N2Q0MTdhMmM=
|
6
|
+
metadata.gz: 37d3cb9b57606e714126a9230d230f7d07036113f9776a45ee123ed043ad779962f906aa91951774a6b5a326ba05ec92c72c898643082ffbc489f9fda01f42ea
|
7
|
+
data.tar.gz: 6e56c2597382974c6d95d1ced2d8af757dd52f53d5349e236b633f4ca925250b6b5106757d226143e8b32e479411d51ae509db2240b4c4f67dec84c9419548bc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Asciiart changelog
|
2
|
+
|
3
|
+
Asciiart follows [Semantic Versioning](https://semver.org/), please see the [README.md](README.md) for details.
|
4
|
+
|
5
|
+
## 0.3.0
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* Ruby 3.1.x compatibility [#13](https://github.com/nodanaonlyzuul/asciiart/issues/13)
|
10
|
+
|
11
|
+
### (semi) Tested Ruby Versions
|
12
|
+
|
13
|
+
I hope to have a better automated test matrix in the future but...
|
14
|
+
|
15
|
+
* ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20]
|
16
|
+
* ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]
|
17
|
+
* ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin20]
|
18
|
+
|
19
|
+
## 0.2.0
|
20
|
+
|
21
|
+
### Notes
|
22
|
+
|
23
|
+
#### Rehabilitation & being a better citizen
|
24
|
+
|
25
|
+
This gem started as a fast-and-loose side project in 2014.
|
26
|
+
It mostly worked for many years, with no need for major updates.
|
27
|
+
In January 2022, I noticed a lot of the gem & its dependencies' syntax didn't play well in modern versions of Ruby.
|
28
|
+
|
29
|
+
#### Tagging & Github Releases
|
30
|
+
|
31
|
+
This is the version where I started caring about using tags & GH releases.
|
32
|
+
|
33
|
+
### Fixed
|
34
|
+
|
35
|
+
* Fixing ability to open a URL via cli.[[#12](https://github.com/nodanaonlyzuul/asciiart/pull/12)]
|
36
|
+
* Fixing color output issues.[[#12](https://github.com/nodanaonlyzuul/asciiart/pull/12)]
|
37
|
+
|
38
|
+
## < 0.2.0
|
39
|
+
|
40
|
+
These were the dark ages.
|
41
|
+
I'm sorry.
|
data/README.md
CHANGED
@@ -153,11 +153,11 @@ Remote Images
|
|
153
153
|
|
154
154
|
Output it as HTML
|
155
155
|
|
156
|
-
$
|
156
|
+
$ asciiart -c -f html ~/Ross/cppsource/secret/noopen/sillhere?/turnback/bea-arthur-birthdaysuit.jpg > ~/Desktop/ascii-as-html.html
|
157
157
|
|
158
158
|
_or smaller_
|
159
159
|
|
160
|
-
$
|
160
|
+
$ asciiart -w 50 -c -f html ~/Stephen/boringSQLsnippets/nothingtoseehere/turnback/bea-arthur-with-ross's-head.jpg > ~/Desktop/saturdaynight.html
|
161
161
|
|
162
162
|
Get Help
|
163
163
|
|
data/asciiart.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'asciiart/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "asciiart"
|
8
8
|
gem.version = AsciiArt::VERSION
|
9
|
-
gem.authors = ["nodanaonlyzuul", "rosscooperman"]
|
9
|
+
gem.authors = ["nodanaonlyzuul", "rosscooperman", "caderaspindrift", "wendy0402"]
|
10
10
|
gem.email = ["stephen@eastmedia.com"]
|
11
11
|
# gem.description = %q{A command line tool to turn images into ASCII art}
|
12
12
|
gem.summary = %q{A command line tool to turn images into ASCII art}
|
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_dependency('rmagick')
|
21
|
-
gem.add_dependency('rainbow',
|
20
|
+
gem.add_dependency('rmagick', '4.2.4')
|
21
|
+
gem.add_dependency('rainbow', '3.0.0')
|
22
22
|
|
23
23
|
gem.add_development_dependency('pry')
|
24
24
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AsciiRenderer
|
2
|
+
class Html
|
3
|
+
def initialize(img)
|
4
|
+
@img = img
|
5
|
+
@quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_ascii_art(options = {})
|
9
|
+
width = options[:width]
|
10
|
+
scale = (width.to_f / @img.columns)
|
11
|
+
height = ((@img.rows * scale) / 2).to_i
|
12
|
+
|
13
|
+
img = @img.resize(width, height)
|
14
|
+
@color_img = img.dup if options[:color]
|
15
|
+
img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
|
16
|
+
border = "+#{'-' * width}+<br/>"
|
17
|
+
border = html_char(border)
|
18
|
+
|
19
|
+
output = border.dup
|
20
|
+
|
21
|
+
img.view(0, 0, width, height) do |view|
|
22
|
+
height.times do |i|
|
23
|
+
output << '|'
|
24
|
+
width.times { |j| output << pixel_to_char(view, j: j, i: i, color: options[:color]) }
|
25
|
+
output << "|<br/>"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
output + border
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def pixel_to_char(view, args = {})
|
33
|
+
pixel = view[args[:i]][args[:j]]
|
34
|
+
character = image_chars[pixel.red/@quantum_calc]
|
35
|
+
|
36
|
+
if (args[:color])
|
37
|
+
|
38
|
+
pix = @color_img.pixel_color(args[:j],args[:i])
|
39
|
+
color_string = "color: #{pix.to_color( Magick::AllCompliance,false,8, true)};"
|
40
|
+
else
|
41
|
+
color_string = ""
|
42
|
+
end
|
43
|
+
|
44
|
+
html_char(character, color_string)
|
45
|
+
end
|
46
|
+
|
47
|
+
def image_chars
|
48
|
+
@image_chars ||= " .~:+=o*x^%\#@$WQ".chars.to_a.map{ |char| char == " " ? " " : char}
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def html_char(char, additional_style = "")
|
53
|
+
"<span style=\"font-family: 'Lucida Console', Monaco, monospace; #{additional_style}\">#{char}</span>"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module AsciiRenderer
|
2
|
+
class Text
|
3
|
+
def initialize(img)
|
4
|
+
@img = img
|
5
|
+
@quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_ascii_art(options = {})
|
9
|
+
width = options[:width]
|
10
|
+
scale = (width.to_f / @img.columns)
|
11
|
+
height = ((@img.rows * scale) / 2).to_i
|
12
|
+
|
13
|
+
img = @img.resize(width, height)
|
14
|
+
@colored_img = img.dup if options[:color]
|
15
|
+
img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
|
16
|
+
|
17
|
+
border = "+#{'-' * width}+\n"
|
18
|
+
output = border.dup
|
19
|
+
|
20
|
+
img.view(0, 0, width, height) do |view|
|
21
|
+
height.times do |i|
|
22
|
+
output << '|'
|
23
|
+
width.times { |j| output << pixel_to_char(view,j: j , i: i, color: options[:color] ) }
|
24
|
+
output << "|\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
output + border
|
28
|
+
end
|
29
|
+
|
30
|
+
def pixel_to_char(view, args = {})
|
31
|
+
pixel = view[args[:i]][args[:j]]
|
32
|
+
character = image_chars[pixel.red/@quantum_calc]
|
33
|
+
|
34
|
+
if args[:color]
|
35
|
+
pix = @colored_img.pixel_color(args[:j],args[:i])
|
36
|
+
character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
|
37
|
+
end
|
38
|
+
character
|
39
|
+
end
|
40
|
+
|
41
|
+
def image_chars
|
42
|
+
@image_chars ||= " .~:+=o*x^%\#@$WQ".chars.to_a
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def unified_rgb_value(number)
|
47
|
+
if defined?(Magick::QuantumDepth)
|
48
|
+
num = (Magick::QuantumDepth == 16) ? (number / 256) : number
|
49
|
+
else
|
50
|
+
num = (Magick::QuantumRange == 65535) ? (number / 256) : number
|
51
|
+
end
|
52
|
+
(num > 255) ? 255 : num
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/asciiart/version.rb
CHANGED
data/lib/asciiart.rb
CHANGED
@@ -1,94 +1,27 @@
|
|
1
1
|
require "asciiart/version"
|
2
|
-
require '
|
2
|
+
require 'rmagick'
|
3
3
|
require 'uri'
|
4
4
|
require 'open-uri'
|
5
5
|
require 'rainbow'
|
6
6
|
require 'rainbow/ext/string'
|
7
7
|
|
8
|
+
require File.expand_path("../asciiart/html", __FILE__)
|
9
|
+
require File.expand_path("../asciiart/text", __FILE__)
|
10
|
+
|
8
11
|
class AsciiArt
|
9
12
|
|
10
13
|
attr_writer :image_chars
|
11
14
|
|
12
15
|
def initialize(path_to_file)
|
13
16
|
# open-uri open will fallback to IO open
|
14
|
-
open(path_to_file) { |file| @data = file.read }
|
17
|
+
URI.open(path_to_file) { |file| @data = file.read }
|
15
18
|
self
|
16
19
|
end
|
17
20
|
|
18
21
|
def to_ascii_art(options = {})
|
19
22
|
options = { width: 100, color: false, format: "text" }.merge(options)
|
20
|
-
|
21
23
|
img = Magick::Image.from_blob(@data).first
|
22
|
-
|
23
|
-
|
24
|
-
scale = (width.to_f / img.columns)
|
25
|
-
height = ((img.rows * scale) / 2).to_i
|
26
|
-
|
27
|
-
img.resize!(width, height)
|
28
|
-
color_image = img.dup if options[:color]
|
29
|
-
img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
|
30
|
-
quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
|
31
|
-
image_chars.map! {|char| char == " " ? " " : char } if options[:format] == "html"
|
32
|
-
|
33
|
-
border = "+#{'-' * width}+#{line_break(options[:format])}"
|
34
|
-
border = html_char(border) if options[:format] == "html"
|
35
|
-
|
36
|
-
output = border.dup
|
37
|
-
|
38
|
-
img.view(0, 0, width, height) do |view|
|
39
|
-
height.times do |i|
|
40
|
-
output << '|'
|
41
|
-
width.times do |j|
|
42
|
-
|
43
|
-
character = image_chars[view[i][j].red/quantum_calc]
|
44
|
-
|
45
|
-
if options[:format] == "html"
|
46
|
-
if (options[:color])
|
47
|
-
|
48
|
-
pix = color_image.pixel_color(j,i)
|
49
|
-
color_string = "color: #{pix.to_color( Magick::AllCompliance,false,8, true)};"
|
50
|
-
else
|
51
|
-
color_string = ""
|
52
|
-
end
|
53
|
-
character = html_char(character, color_string)
|
54
|
-
else
|
55
|
-
# text-format
|
56
|
-
if options[:color]
|
57
|
-
pix = color_image.pixel_color(j,i)
|
58
|
-
character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
output << character
|
63
|
-
end
|
64
|
-
|
65
|
-
output << "|#{line_break(options[:format])}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
output + border
|
70
|
-
end
|
71
|
-
|
72
|
-
def image_chars
|
73
|
-
@image_chars ||= ' .~:+=o*x^%#@$MW'.chars.to_a
|
74
|
-
end
|
75
|
-
|
76
|
-
def inspect
|
77
|
-
"#<#{self.class.to_s}>"
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def line_break(format)
|
83
|
-
(format == "text") ? "\n" : "<br/>"
|
84
|
-
end
|
85
|
-
|
86
|
-
def unified_rgb_value(number)
|
87
|
-
(Magick::QuantumDepth == 16) ? (number / 256) : number
|
88
|
-
end
|
89
|
-
|
90
|
-
def html_char(char, additional_style = "")
|
91
|
-
"<span style=\"font-family: 'Lucida Console', Monaco, monospace; #{additional_style}\">#{char}</span>"
|
24
|
+
renderer = (options[:format] == "text" ? AsciiRenderer::Text.new(img) : AsciiRenderer::Html.new(img))
|
25
|
+
renderer.to_ascii_art(options)
|
92
26
|
end
|
93
27
|
end
|
94
|
-
|
metadata
CHANGED
@@ -1,59 +1,61 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciiart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nodanaonlyzuul
|
8
8
|
- rosscooperman
|
9
|
-
|
9
|
+
- caderaspindrift
|
10
|
+
- wendy0402
|
11
|
+
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
14
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: rmagick
|
16
18
|
requirement: !ruby/object:Gem::Requirement
|
17
19
|
requirements:
|
18
|
-
- -
|
20
|
+
- - '='
|
19
21
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
22
|
+
version: 4.2.4
|
21
23
|
type: :runtime
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
24
26
|
requirements:
|
25
|
-
- -
|
27
|
+
- - '='
|
26
28
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
29
|
+
version: 4.2.4
|
28
30
|
- !ruby/object:Gem::Dependency
|
29
31
|
name: rainbow
|
30
32
|
requirement: !ruby/object:Gem::Requirement
|
31
33
|
requirements:
|
32
34
|
- - '='
|
33
35
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
36
|
+
version: 3.0.0
|
35
37
|
type: :runtime
|
36
38
|
prerelease: false
|
37
39
|
version_requirements: !ruby/object:Gem::Requirement
|
38
40
|
requirements:
|
39
41
|
- - '='
|
40
42
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
43
|
+
version: 3.0.0
|
42
44
|
- !ruby/object:Gem::Dependency
|
43
45
|
name: pry
|
44
46
|
requirement: !ruby/object:Gem::Requirement
|
45
47
|
requirements:
|
46
|
-
- -
|
48
|
+
- - ">="
|
47
49
|
- !ruby/object:Gem::Version
|
48
50
|
version: '0'
|
49
51
|
type: :development
|
50
52
|
prerelease: false
|
51
53
|
version_requirements: !ruby/object:Gem::Requirement
|
52
54
|
requirements:
|
53
|
-
- -
|
55
|
+
- - ">="
|
54
56
|
- !ruby/object:Gem::Version
|
55
57
|
version: '0'
|
56
|
-
description:
|
58
|
+
description:
|
57
59
|
email:
|
58
60
|
- stephen@eastmedia.com
|
59
61
|
executables:
|
@@ -61,7 +63,8 @@ executables:
|
|
61
63
|
extensions: []
|
62
64
|
extra_rdoc_files: []
|
63
65
|
files:
|
64
|
-
- .gitignore
|
66
|
+
- ".gitignore"
|
67
|
+
- CHANGELOG.md
|
65
68
|
- Gemfile
|
66
69
|
- LICENSE.txt
|
67
70
|
- README.md
|
@@ -69,28 +72,29 @@ files:
|
|
69
72
|
- asciiart.gemspec
|
70
73
|
- bin/asciiart
|
71
74
|
- lib/asciiart.rb
|
75
|
+
- lib/asciiart/html.rb
|
76
|
+
- lib/asciiart/text.rb
|
72
77
|
- lib/asciiart/version.rb
|
73
78
|
homepage: https://github.com/nodanaonlyzuul/asciiart
|
74
79
|
licenses: []
|
75
80
|
metadata: {}
|
76
|
-
post_install_message:
|
81
|
+
post_install_message:
|
77
82
|
rdoc_options: []
|
78
83
|
require_paths:
|
79
84
|
- lib
|
80
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
86
|
requirements:
|
82
|
-
- -
|
87
|
+
- - ">="
|
83
88
|
- !ruby/object:Gem::Version
|
84
89
|
version: '0'
|
85
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
91
|
requirements:
|
87
|
-
- -
|
92
|
+
- - ">="
|
88
93
|
- !ruby/object:Gem::Version
|
89
94
|
version: '0'
|
90
95
|
requirements: []
|
91
|
-
|
92
|
-
|
93
|
-
signing_key:
|
96
|
+
rubygems_version: 3.3.3
|
97
|
+
signing_key:
|
94
98
|
specification_version: 4
|
95
99
|
summary: A command line tool to turn images into ASCII art
|
96
100
|
test_files: []
|