asciiart 0.0.7 → 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 34e508f6e6ac680c5efa0b9c2d962017825ab9706f4c3f10449d411bce37c5d5
4
+ data.tar.gz: bfe96d2e79431f8f54a908040083c5f74c9fe45a6c2d221297c9803a16543dd2
5
+ SHA512:
6
+ metadata.gz: 7c15cbdbc1aa10708815e59490e5ba9003e0484f742b2a0bddd319006db6355a426b84a06328bf5d0f4eb154da8d6695b33277c6b3bca65d30c679159a558dd4
7
+ data.tar.gz: 909ec83731b16b70a93404c975cefaea83ce411308d0f9a75d8afefaa6215f9664fe29e267ca5858d950a7d509c4dbfb31be071c3a1ff120a4fe1485dacd81b4
data/README.md CHANGED
@@ -153,11 +153,11 @@ Remote Images
153
153
 
154
154
  Output it as HTML
155
155
 
156
- $ be asciiart -c -f html ~/Ross/cppsource/secret/noopen/sillhere?/turnback/bea-arthur-birthdaysuit.jpg > ~/Desktop/ascii-as-html.html
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
- $ be asciiart -w 50 -c -f html ~/Stephen/boringSQLsnippets/nothingtoseehere/turnback/bea-arthur-with-ross's-head.jpg > ~/Desktop/saturdaynight.html
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.1.2')
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 == " " ? "&nbsp" : 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
@@ -1,3 +1,3 @@
1
1
  class AsciiArt
2
- VERSION = "0.0.7"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/asciiart.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require "asciiart/version"
2
- require 'RMagick'
2
+ require 'rmagick'
3
3
  require 'uri'
4
4
  require 'open-uri'
5
5
  require 'rainbow'
6
+ require 'rainbow/ext/string'
7
+
8
+ require File.expand_path("../asciiart/html", __FILE__)
9
+ require File.expand_path("../asciiart/text", __FILE__)
6
10
 
7
11
  class AsciiArt
8
12
 
@@ -10,84 +14,14 @@ class AsciiArt
10
14
 
11
15
  def initialize(path_to_file)
12
16
  # open-uri open will fallback to IO open
13
- open(path_to_file) { |file| @data = file.read }
17
+ URI.open(path_to_file) { |file| @data = file.read }
14
18
  self
15
19
  end
16
20
 
17
21
  def to_ascii_art(options = {})
18
22
  options = { width: 100, color: false, format: "text" }.merge(options)
19
-
20
23
  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 == " " ? "&nbsp;" : 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
- (Magick::QuantumDepth == 16) ? (number / 256) : number
87
- end
88
-
89
- def html_char(char, additional_style = "")
90
- "<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)
91
26
  end
92
27
  end
93
-
metadata CHANGED
@@ -1,66 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciiart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - nodanaonlyzuul
9
8
  - rosscooperman
10
- autorequire:
9
+ - caderaspindrift
10
+ - wendy0402
11
+ autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2013-11-22 00:00:00.000000000 Z
14
+ date: 2022-01-10 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rmagick
17
18
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
19
  requirements:
20
- - - ! '>='
20
+ - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: '0'
22
+ version: 4.1.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
26
  requirements:
28
- - - ! '>='
27
+ - - '='
29
28
  - !ruby/object:Gem::Version
30
- version: '0'
29
+ version: 4.1.2
31
30
  - !ruby/object:Gem::Dependency
32
31
  name: rainbow
33
32
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
33
  requirements:
36
- - - ! '>='
34
+ - - '='
37
35
  - !ruby/object:Gem::Version
38
- version: '0'
36
+ version: 3.0.0
39
37
  type: :runtime
40
38
  prerelease: false
41
39
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
40
  requirements:
44
- - - ! '>='
41
+ - - '='
45
42
  - !ruby/object:Gem::Version
46
- version: '0'
43
+ version: 3.0.0
47
44
  - !ruby/object:Gem::Dependency
48
45
  name: pry
49
46
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
47
  requirements:
52
- - - ! '>='
48
+ - - ">="
53
49
  - !ruby/object:Gem::Version
54
50
  version: '0'
55
51
  type: :development
56
52
  prerelease: false
57
53
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
54
  requirements:
60
- - - ! '>='
55
+ - - ">="
61
56
  - !ruby/object:Gem::Version
62
57
  version: '0'
63
- description:
58
+ description:
64
59
  email:
65
60
  - stephen@eastmedia.com
66
61
  executables:
@@ -68,7 +63,7 @@ executables:
68
63
  extensions: []
69
64
  extra_rdoc_files: []
70
65
  files:
71
- - .gitignore
66
+ - ".gitignore"
72
67
  - Gemfile
73
68
  - LICENSE.txt
74
69
  - README.md
@@ -76,29 +71,29 @@ files:
76
71
  - asciiart.gemspec
77
72
  - bin/asciiart
78
73
  - lib/asciiart.rb
74
+ - lib/asciiart/html.rb
75
+ - lib/asciiart/text.rb
79
76
  - lib/asciiart/version.rb
80
77
  homepage: https://github.com/nodanaonlyzuul/asciiart
81
78
  licenses: []
82
- post_install_message:
79
+ metadata: {}
80
+ post_install_message:
83
81
  rdoc_options: []
84
82
  require_paths:
85
83
  - lib
86
84
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
85
  requirements:
89
- - - ! '>='
86
+ - - ">="
90
87
  - !ruby/object:Gem::Version
91
88
  version: '0'
92
89
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
90
  requirements:
95
- - - ! '>='
91
+ - - ">="
96
92
  - !ruby/object:Gem::Version
97
93
  version: '0'
98
94
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 1.8.24
101
- signing_key:
102
- specification_version: 3
95
+ rubygems_version: 3.2.3
96
+ signing_key:
97
+ specification_version: 4
103
98
  summary: A command line tool to turn images into ASCII art
104
99
  test_files: []