asciiart 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -151,16 +151,25 @@ Remote Images
151
151
 
152
152
  $ asciiart http://www.google.com/images/srpr/logo3w.png
153
153
 
154
+ Output it as HTML
155
+
156
+ $ be asciiart -c -f html ~/Ross/cppsource/secret/noopen/sillhere?/turnback/bea-arthur-birthdaysuit.jpg > ~/Desktop/ascii-as-html.html
157
+
158
+ _or smaller_
159
+
160
+ $ be asciiart -w 50 -c -f html ~/Stephen/boringSQLsnippets/nothingtoseehere/turnback/bea-arthur-with-ross's-head.jpg > ~/Desktop/saturdaynight.html
161
+
154
162
  Get Help
155
163
 
156
164
  $ asciiart -h
157
165
 
158
166
  Usage: asciiart [options] <path_or_url>
159
- -w, --width WIDTH Width of the finished Ascii Art (Default: 100)
160
- -c, --color Switch to use colored terminal output (Default: false)
161
- -i, --invert-chars Invert the character map. Depending on your terminal and image this can make the image clearer (or a lot worse)
162
- -v, --version Show AsciiArt version
163
- -h, --help Show this message
167
+ -w, --width WIDTH Width of the finished Ascii Art (Default: 100)
168
+ -f, --format [text/html] output format (Default: text)
169
+ -c, --color Switch to use colored terminal output (Default: false)
170
+ -i, --invert-chars Invert the character map. *Depending on background and image color - this can make the result clearer.*
171
+ -v, --version Show AsciiArt version
172
+ -h, --help Show this message
164
173
 
165
174
  ## Contributing
166
175
 
@@ -13,6 +13,10 @@ opt_parser = OptionParser.new do |opts|
13
13
  options[:width] = width.to_i
14
14
  end
15
15
 
16
+ opts.on('-f', '--format [text/html]', 'output format (Default: text)') do |format|
17
+ options[:format] = format
18
+ end
19
+
16
20
  opts.on('-c', '--color', 'Switch to use colored terminal output (Default: false)') do
17
21
  options[:color] = true
18
22
  end
@@ -15,7 +15,7 @@ class AsciiArt
15
15
  end
16
16
 
17
17
  def to_ascii_art(options = {})
18
- options = { width: 100, color: false }.merge(options)
18
+ options = { width: 100, color: false, format: "text" }.merge(options)
19
19
 
20
20
  img = Magick::Image.from_blob(@data).first
21
21
 
@@ -27,8 +27,11 @@ class AsciiArt
27
27
  color_image = img.dup if options[:color]
28
28
  img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize
29
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"
30
34
 
31
- border = "+#{'-' * width}+\n"
32
35
  output = border.dup
33
36
 
34
37
  img.view(0, 0, width, height) do |view|
@@ -38,14 +41,27 @@ class AsciiArt
38
41
 
39
42
  character = image_chars[view[i][j].red/quantum_calc]
40
43
 
41
- if options[:color]
42
- pix = color_image.pixel_color(j,i)
43
- character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue))
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
44
59
  end
45
60
 
46
61
  output << character
47
62
  end
48
- output << "|\n"
63
+
64
+ output << "|#{line_break(options[:format])}"
49
65
  end
50
66
  end
51
67
 
@@ -62,9 +78,16 @@ class AsciiArt
62
78
 
63
79
  private
64
80
 
81
+ def line_break(format)
82
+ (format == "text") ? "\n" : "<br/>"
83
+ end
84
+
65
85
  def unified_rgb_value(number)
66
86
  (Magick::QuantumDepth == 16) ? (number / 256) : number
67
87
  end
68
88
 
89
+ def html_char(char, additional_style = "")
90
+ "<span style=\"font-family: 'Lucida Console', Monaco, monospace; #{additional_style}\">#{char}</span>"
91
+ end
69
92
  end
70
93
 
@@ -1,3 +1,3 @@
1
1
  class AsciiArt
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciiart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-28 00:00:00.000000000 Z
13
+ date: 2013-11-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rmagick