asciiart 0.0.10 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a8d99e878fcb702b5c8c0fa998f6d3b942f90d19b20e30f6f7f2eff8bce0f88
4
- data.tar.gz: 7eef461cb0b54d2eefb6eac93ea8fc74b846251936b752b2ffcd557ad210e477
3
+ metadata.gz: 34e508f6e6ac680c5efa0b9c2d962017825ab9706f4c3f10449d411bce37c5d5
4
+ data.tar.gz: bfe96d2e79431f8f54a908040083c5f74c9fe45a6c2d221297c9803a16543dd2
5
5
  SHA512:
6
- metadata.gz: 55ac4320bbe7724f765aa492971d890ccb87f079fd544e884df925c48f94df253dd6c2760ba1289bf595434feb9fea3ffbc9e7c6bfde931cc176b048c3a272c5
7
- data.tar.gz: 65ad4c44c57a1d24cfff039a6b63457c7a9528d7c279e1c37710bdca7de7e41fe56f67d02fc555df95bf5759efa81b6100f2adda286501e06fd6ff2f16bd67ec
6
+ metadata.gz: 7c15cbdbc1aa10708815e59490e5ba9003e0484f742b2a0bddd319006db6355a426b84a06328bf5d0f4eb154da8d6695b33277c6b3bca65d30c679159a558dd4
7
+ data.tar.gz: 909ec83731b16b70a93404c975cefaea83ce411308d0f9a75d8afefaa6215f9664fe29e267ca5858d950a7d509c4dbfb31be071c3a1ff120a4fe1485dacd81b4
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", "caderaspindrift"]
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', '2.13.4')
21
- gem.add_dependency('rainbow', '2.0.0')
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.10"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/asciiart.rb CHANGED
@@ -5,94 +5,23 @@ 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
- width = options[:width]
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 == " " ? "&nbsp;" : 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
- if defined?(Magick::QuantumDepth)
88
- return (Magick::QuantumDepth == 16) ? (number / 256) : number
89
- else
90
- return (Magick::QuantumRange == 65535) ? (number / 256) : number
91
- end
92
- end
93
-
94
- def html_char(char, additional_style = "")
95
- "<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)
96
26
  end
97
27
  end
98
-
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciiart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nodanaonlyzuul
8
8
  - rosscooperman
9
9
  - caderaspindrift
10
+ - wendy0402
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2021-02-02 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
@@ -18,28 +19,28 @@ dependencies:
18
19
  requirements:
19
20
  - - '='
20
21
  - !ruby/object:Gem::Version
21
- version: 2.13.4
22
+ version: 4.1.2
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
26
  requirements:
26
27
  - - '='
27
28
  - !ruby/object:Gem::Version
28
- version: 2.13.4
29
+ version: 4.1.2
29
30
  - !ruby/object:Gem::Dependency
30
31
  name: rainbow
31
32
  requirement: !ruby/object:Gem::Requirement
32
33
  requirements:
33
34
  - - '='
34
35
  - !ruby/object:Gem::Version
35
- version: 2.0.0
36
+ version: 3.0.0
36
37
  type: :runtime
37
38
  prerelease: false
38
39
  version_requirements: !ruby/object:Gem::Requirement
39
40
  requirements:
40
41
  - - '='
41
42
  - !ruby/object:Gem::Version
42
- version: 2.0.0
43
+ version: 3.0.0
43
44
  - !ruby/object:Gem::Dependency
44
45
  name: pry
45
46
  requirement: !ruby/object:Gem::Requirement
@@ -70,6 +71,8 @@ files:
70
71
  - asciiart.gemspec
71
72
  - bin/asciiart
72
73
  - lib/asciiart.rb
74
+ - lib/asciiart/html.rb
75
+ - lib/asciiart/text.rb
73
76
  - lib/asciiart/version.rb
74
77
  homepage: https://github.com/nodanaonlyzuul/asciiart
75
78
  licenses: []
@@ -89,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
92
  - !ruby/object:Gem::Version
90
93
  version: '0'
91
94
  requirements: []
92
- rubygems_version: 3.0.8
95
+ rubygems_version: 3.2.3
93
96
  signing_key:
94
97
  specification_version: 4
95
98
  summary: A command line tool to turn images into ASCII art