ImageText 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/bin/imagetext +12 -0
  3. data/lib/ImageText.rb +36 -0
  4. data/lib/helpers.rb +18 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae13609c03f7331d5e30cc8f4a82744cd3facc4f
4
+ data.tar.gz: 682d2a6f8aeb795963157266a81ee3ef5f1ef976
5
+ SHA512:
6
+ metadata.gz: e92b80ebee44d6dfc4f07ede1b291b7c8f5661fb130129035180548804faa3141fc6b6c30902a157297c890c3742afee421c80f2dba9d06612b7ad0d69547c9b
7
+ data.tar.gz: 707adef35faa15a17eff8e9bf4d815af58d4160a8491eb79e31300102848064747b5ff7004a03cb0adca63f863289fca2e146c4c88e27fc58557793bb59ff459
data/bin/imagetext ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ require "ImageText"
3
+
4
+ if !ARGV.length.between?(1,2)
5
+ puts "Bad input"
6
+ exit
7
+ end
8
+
9
+ width = ARGV.length == 2 ? ARGV[1] : 100
10
+ IT = ImageText.new(ARGV[0], width)
11
+
12
+ print IT.texify()
data/lib/ImageText.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'RMagick'
3
+ require 'helpers.rb'
4
+ include Magick
5
+
6
+ class ImageText
7
+ @@chars = " .,-_*^+=?$&%Q@\#"
8
+ @@maxchar = @@chars.length - 1
9
+
10
+ def initialize(image, max_width=150.0)
11
+ puts "No image" if not File.exist?(image)
12
+ @img = ImageList.new(image).average
13
+
14
+ scale = [(max_width.to_f / @img.columns), 1.0].min
15
+ @img.scale!(scale)
16
+ end
17
+
18
+ def texify()
19
+ text = ""
20
+ @img.each_pixel do
21
+ |pixel, x, y|
22
+
23
+ text += "\n" if (x == @img.columns - 1)
24
+
25
+ colour = pixel.to_color(AllCompliance, false, QuantumDepth, true)
26
+
27
+ gScale = gray_scale(colour);
28
+ #puts @@chars.length
29
+ #puts gScale
30
+ #puts ((@@chars.length) * gScale)
31
+ text += @@chars[(@@maxchar * gScale).round]
32
+
33
+ end
34
+ return text
35
+ end
36
+ end
data/lib/helpers.rb ADDED
@@ -0,0 +1,18 @@
1
+
2
+ #Average out the reds, greens and blues
3
+ def average_colour(hex)
4
+ hex[0] = "" if hex[0] == "\#"
5
+ depth = hex.length / 3
6
+ total = 0
7
+ 3.times do
8
+ |i|
9
+ total += hex.slice(i*depth, 4).to_i(16)
10
+ end
11
+ return total / 3.0
12
+ end
13
+
14
+
15
+ #On a scale of 0 (black) to 1 (white), how gray is it
16
+ def gray_scale(hex)
17
+ return average_colour(hex) / "FFFF".to_i(16)
18
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ImageText
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Arsham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Turn images into ASCII art
14
+ email: arsham.faghihi@gmail.com
15
+ executables:
16
+ - imagetext
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/helpers.rb
21
+ - lib/ImageText.rb
22
+ - bin/imagetext
23
+ homepage: http://arsh.am
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.14
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: ImageText
47
+ test_files: []