asciiart 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .redcar
6
+ .rvmrc
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # List gem dependencies in gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eastmedia
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # AsciiArt By:
2
+
3
+ +----------------------------------------------------------------------------------------------------+
4
+ |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
5
+ |oo: ~oooo~ +oooo+:~ :o~ ~ :+ ~oooo+ ~o+ o+ ~+ooo~ ~oooo: :oooooo|
6
+ |oo: +oooooooo: : +ooo ~+oo+:+oooo: +ooo+ :oo+ ~o+ +oooooo+ +oo++~ +o~ :ooo+ : :ooooo|
7
+ |oo: ~ ~~ :oo+ +o: ooo+ ~~+ooooo: +ooo+ +~ +o +~ ~o+ ~ ~ ~o+ +ooooo ~o~ ~oo+ :o+ +oooo|
8
+ |oo: +++++oo+ ::: ~ooooo+++~ +ooo+ oooo+ +o +o ~o+ ++++++o+ +oooo+ :o :oo ::: oooo|
9
+ |oo: ::::::+ ~::~~: ~o ~:::~ oooo: +ooo+ +o+ :oo ~o+ ~:::::o+ ~::~ +oo ~o :~:~: ooo|
10
+ |oo+::::::::+::oooooo+::oo+:::~:+ooooo+::ooooo::ooo++ooo+:+oo::::::::oo::::::++oooo+:+o::+oooooo::+oo|
11
+ |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo|
12
+ +----------------------------------------------------------------------------------------------------+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'asciiart'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install asciiart
27
+
28
+ ## Usage
29
+
30
+ ### In Code
31
+
32
+ require 'asciiart'
33
+ a = AsciiArt.new("/Users/sschor/Desktop/uncle_larry.jpg")
34
+ => #<AsciiArt:0x00000100878678 @file=#<File:/Users/sschor/Desktop/uncle_larry.jpg>>
35
+ puts a.to_ascii_art
36
+ => ...untold glory follows
37
+
38
+ ### In The Command Line
39
+
40
+ Local Files
41
+
42
+ $ asciiart ~/Desktop/uncle_larry.jpg
43
+
44
+ Remote Images
45
+
46
+ $ asciiart http://www.google.com/images/srpr/logo3w.png
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/asciiart.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asciiart/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "asciiart"
8
+ gem.version = AsciiArt::VERSION
9
+ gem.authors = ["nodanaonlyzuul"]
10
+ gem.email = ["stephen@eastmedia.com"]
11
+ # gem.description = %q{A command line tool to turn images into ASCII art}
12
+ gem.summary = %q{A command line tool to turn images into ASCII art}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('rmagick')
21
+
22
+ gem.add_development_dependency('pry')
23
+ end
data/bin/asciiart ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'uri'
4
+ require 'tempfile'
5
+ require 'net/http'
6
+ require 'asciiart'
7
+
8
+ if ARGV[0].nil?
9
+ puts "Specify a path or URL to convert\n"
10
+ exit
11
+ end
12
+
13
+ if ARGV[0] =~ URI::regexp
14
+ temp_file = Tempfile.new(File.basename(ARGV[0]))
15
+ puts "\n...hold up, downloading...\n"
16
+ temp_file << Net::HTTP.get_response(URI.parse(ARGV[0])).body
17
+ temp_file.close
18
+
19
+ puts AsciiArt.new(temp_file.path).to_ascii_art
20
+ temp_file.delete
21
+ else
22
+ file_to_convert = AsciiArt.new(ARGV[0])
23
+ puts file_to_convert.to_ascii_art
24
+ end
data/lib/asciiart.rb ADDED
@@ -0,0 +1,50 @@
1
+ require "asciiart/version"
2
+ require 'RMagick'
3
+
4
+ class AsciiArt
5
+
6
+ attr_accessor :file
7
+ attr_writer :image_chars
8
+
9
+ def initialize(path_to_file)
10
+ @file = File.new(path_to_file, "r")
11
+ end
12
+
13
+ def to_ascii_art
14
+
15
+ img = Magick::Image.read(file).first
16
+
17
+ new_width = 100
18
+ scale = (new_width.to_f / img.columns)
19
+ new_height = ((img.rows * scale) / 2).to_i
20
+
21
+ img.resize!(new_width, new_height)
22
+
23
+ img = img.quantize(image_chars.length, Magick::GRAYColorspace)
24
+ img = img.normalize
25
+
26
+ quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i
27
+
28
+ output = ""
29
+
30
+ border = '+' + ('-' * new_width) + '+' + "\n"
31
+ output << border
32
+
33
+ img.view(0, 0, new_width, new_height) do |view|
34
+ new_height.times do |i|
35
+ output << '|'
36
+ new_width.times { |j| output << image_chars[view[i][j].red/quantum_calc] }
37
+ output << "|\n"
38
+ end
39
+ end
40
+
41
+ output << border
42
+
43
+ output
44
+ end
45
+
46
+ def image_chars
47
+ @image_chars ||= [" ", ".", "~", ":", "+", "=", "o", "*", "x", "^", "%", "#", "@", "$", "M", "W"]
48
+ end
49
+
50
+ end
@@ -0,0 +1,3 @@
1
+ class AsciiArt
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asciiart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nodanaonlyzuul
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rmagick
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email:
48
+ - stephen@eastmedia.com
49
+ executables:
50
+ - asciiart
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - asciiart.gemspec
60
+ - bin/asciiart
61
+ - lib/asciiart.rb
62
+ - lib/asciiart/version.rb
63
+ homepage: ''
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: A command line tool to turn images into ASCII art
87
+ test_files: []