asciiart-0.0.10/0000755000004100000410000000000014010032761013411 5ustar www-datawww-dataasciiart-0.0.10/README.md0000644000004100000410000002462214010032761014676 0ustar www-datawww-data# Developed At: +----------------------------------------------------------------------------------------------------+ |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oo: ~oooo~ +oooo+:~ :o~ ~ :+ ~oooo+ ~o+ o+ ~+ooo~ ~oooo: :oooooo| |oo: +oooooooo: : +ooo ~+oo+:+oooo: +ooo+ :oo+ ~o+ +oooooo+ +oo++~ +o~ :ooo+ : :ooooo| |oo: ~ ~~ :oo+ +o: ooo+ ~~+ooooo: +ooo+ +~ +o +~ ~o+ ~ ~ ~o+ +ooooo ~o~ ~oo+ :o+ +oooo| |oo: +++++oo+ ::: ~ooooo+++~ +ooo+ oooo+ +o +o ~o+ ++++++o+ +oooo+ :o :oo ::: oooo| |oo: ::::::+ ~::~~: ~o ~:::~ oooo: +ooo+ +o+ :oo ~o+ ~:::::o+ ~::~ +oo ~o :~:~: ooo| |oo+::::::::+::oooooo+::oo+:::~:+ooooo+::ooooo::ooo++ooo+:+oo::::::::oo::::::++oooo+:+o::+oooooo::+oo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| +----------------------------------------------------------------------------------------------------+ ## Installation Add this line to your application's Gemfile: gem 'asciiart' And then execute: $ bundle Or install it yourself as: $ gem install asciiart ## Usage ### In Code require 'asciiart' a = AsciiArt.new("/Users/sschor/Desktop/uncle_larry.jpg") => #> puts a.to_ascii_art => ...untold glory follows _or_ require 'asciiart' a = AsciiArt.new("https://f.cloud.github.com/assets/54012/36827/2081922c-5377-11e2-9e39-3fafca0cdb79.png") => # puts a.to_ascii_art +----------------------------------------------------------------------------------------------------+ |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooooooooooooooooo++oo+++++++o+o+oooooooooooooooooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooooooooooo++++++++::::::::::+:+++++++oooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooo+++::~~~......... . ........~~~::+++oooooooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooo++++:~~. .~~:++++ooooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooo++:~~. ....~~~~~~~~~~~.... .~~:+++oooooooooooooooooooooooooooooo| |oooooooooooooooooooo+++:~ .~~:::+++++o+++++++::~~.. .~:++ooooooooooooooooooooooooooooo| |oooooooooooooooooo++::~. .~~:::+++o+oooooooooo+++++:::~~.. .~::++oooooooooooooooooooooooooo| |ooooooooooooooooo++:~. .~+++oooooooooooooooooooooooooo++:~. .~:++ooooooooooooooooooooooooo| |ooooooooooooooo++:~.. .~~:+++oooooooooooooooooooooooooo+++:~~. ..~:+oooooooooooooooooooooooo| |ooooooooooooooo+:~. .~:+++::+++++ooooooo+ooooooooooo++++::++::~. ..:++oooooooooooooooooooooo| |ooooooooooooo+++~. .~::+++:~~~~~~:::::::::~~~::::::::~~.~.~::++:~~. ~:+oooooooooooooooooooooo| |ooooooooooo+++:~. ~::++++:. ... ... .~~::++::~. .~:++oooooooooooooooooooo| |oooooooooooo+:~.. ..:++o+++:. .~:+++++:. ..~:++ooooooooooooooooooo| |ooooooooooo+::.. ..:++ooo+:~. .~:+ooo++~~. ...~:+ooooooooooooooooooo| |ooooooooooo+:~. ...~:+ooo++:~. ..~:++oo+:~.. ..:+ooooooooooooooooooo| |oooooooooo++~. . .~:++o++:~~. ..~++o++:~.. .:+ooooooooooooooooooo| |ooooooooooo:~. .~::+oo++~~ ~:+o+++:. .~++oooooooooooooooooo| |oooooooooo++:. .~::++o+:~. .~++oo++:~. .:+o+ooooooooooooooooo| |ooooooooooo:~. ...::+oo+:~. ~:+oo++:~. .:+++ooooooooooooooooo| |oooooooooo++:. .~:+++o+:~ .~++o++:~~ .~+ooooooooooooooooooo| |ooooooooooo+~. .~~:+ooo+~. .~:+o+++~~. .~+ooooooooooooooooooo| |ooooooooooo:~.. .~:+++++~~. .~+o+o+:~. .:++oooooooooooooooooo| |ooooooooooo+~.. ..~:++o+::.. .~:+oo++:~. ~:+ooooooooooooooooooo| |ooooooooooo++~... .~++oo+::~. ~~++o++:~. ..~:+ooooooooooooooooooo| |ooooooooooo++:~. .:+++o++:~. ..~:+++oo+~. ..~:+oooooooooooooooooooo| |oooooooooooo++::. ..~:++oo++::~~~. ...~~::+++o++:~~ ..~:+++ooooooooooooooooooo| |ooooooooooooo+++~. ..::+oo+o++++:~. .~::+++oo++++:~. .:++o+oooooooooooooooooooo| |ooooooooooooooo+:~. .~:++ooooo++:~. .~:+o+oooo++:~.. .~:++oooooooooooooooooooooo| |ooooooooooooooo++::~. .~~:++ooooo+:. .:++oooo++:~~. ..~:+oooooooooooooooooooooooo| |ooooooooooooooooo++::. .~~::+++:~. .~++o+::~~.. .~:++ooooooooooooooooooooooooo| |ooooooooooooooooooo++:.. .~::::~. .~:::~~.. .~:++ooooooooooooooooooooooooooo| |oooooooooooooooooooo+++:~~.. .... .... ..~~:++oooooooooooooooooooooooooooo| |ooooooooooooooooooooooo+++:~~. ..~:++oooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooo+++:~~~.... ...~~::++++oooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooooooo+++++::~~.... . .....~~:::+++oooooooooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooooooooooo+++++::::~:~:~::~:::::++++ooooooooooooooooooooooooooooooooooooooooo| |ooooooooooooooooooooooooooooooooooooo+oo+oo+o++o+oo+oooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| +----------------------------------------------------------------------------------------------------+ => nil _or make it thinner_ require 'asciiart' a = AsciiArt.new("https://f.cloud.github.com/assets/54012/36827/2081922c-5377-11e2-9e39-3fafca0cdb79.png") => # print a.to_ascii_art(width: 50) +--------------------------------------------------+ |oooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooo===++++====ooooooooooooooooooooo| |ooooooooooooo=+:~.~........~~~:+=ooooooooooooooooo| |oooooooooo==:~...~~:++++++:~~..~~:+=oooooooooooooo| |oooooooo=+:...~++====oooo====+:~..~:+=oooooooooooo| |ooooooo=+~..~:++==ooooooooooo=++:~..~+=ooooooooooo| |oooooo=+~.~:+=+~.~~~~~~~~:~~~.~:++:~.~+=oooooooooo| |ooooo=+~~.+===~................~+==:.~~+=ooooooooo| |ooooo=:~~:+=+:~................~~+=+:~.:=ooooooooo| |ooooo=~.~+==+~...................+==+~.:=ooooooooo| |ooooo=~~~+==:~...................:==+~.:=ooooooooo| |ooooo=~~~:==+~..................~+==+~.~=ooooooooo| |ooooo=:~~~+=++~.................:+=+~~~:=ooooooooo| |ooooo=+:..~+==+~~...........~~~+==+~..:+=ooooooooo| |ooooooo+:..~:+=o=+:........:+====:~.~:==oooooooooo| |oooooooo=+~.~~:+==+~......~+==+:~..~:+oooooooooooo| |ooooooooo=+:~..~~:~~.......~:~~..~:+oooooooooooooo| |oooooooooooo=+~~..............~:+=oooooooooooooooo| |ooooooooooooooo==++:~~~~~~:++==ooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooo| |oooooooooooooooooooooooooooooooooooooooooooooooooo| +--------------------------------------------------+ Add color with the "color" option require 'asciiart' a = AsciiArt.new("http://www.evangogh.org/images/paintings/self-portrait.jpg") => # puts a.to_ascii_art(color: true) => [Booyah!](http://farm9.staticflickr.com/8080/8424360420_8011af48fe_b.jpg) ### In The Command Line Local Files $ asciiart ~/Desktop/uncle_larry.jpg Remote Images $ asciiart http://www.google.com/images/srpr/logo3w.png Output it as HTML $ asciiart -c -f html ~/Ross/cppsource/secret/noopen/sillhere?/turnback/bea-arthur-birthdaysuit.jpg > ~/Desktop/ascii-as-html.html _or smaller_ $ asciiart -w 50 -c -f html ~/Stephen/boringSQLsnippets/nothingtoseehere/turnback/bea-arthur-with-ross's-head.jpg > ~/Desktop/saturdaynight.html Get Help $ asciiart -h Usage: asciiart [options] -w, --width WIDTH Width of the finished Ascii Art (Default: 100) -f, --format [text/html] output format (Default: text) -c, --color Switch to use colored terminal output (Default: false) -i, --invert-chars Invert the character map. *Depending on background and image color - this can make the result clearer.* -v, --version Show AsciiArt version -h, --help Show this message ## Requirements This app requires Ruby 1.9 ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request asciiart-0.0.10/bin/0000755000004100000410000000000014010032761014161 5ustar www-datawww-dataasciiart-0.0.10/bin/asciiart0000755000004100000410000000247314010032761015714 0ustar www-datawww-data#!/usr/bin/env ruby require 'asciiart' require 'optparse' options = {} invert_chars = false opt_parser = OptionParser.new do |opts| opts.banner = 'Usage: asciiart [options] ' opts.on('-w', '--width WIDTH', 'Width of the finished Ascii Art (Default: 100)') do |width| options[:width] = width.to_i end opts.on('-f', '--format [text/html]', 'output format (Default: text)') do |format| options[:format] = format end opts.on('-c', '--color', 'Switch to use colored terminal output (Default: false)') do options[:color] = true end opts.on('-i', '--invert-chars', 'Invert the character map. Depending on your terminal and image this can make the image clearer (or a lot worse)') do invert_chars = true end opts.on_tail('-v', '--version', 'Show AsciiArt version') do puts 'AsciiArt version ' + AsciiArt::VERSION exit end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end begin opt_parser.parse! rescue OptionParser::MissingArgument => e puts "ERROR: #{e.message.capitalize}\n#{opt_parser}" exit end if ARGV.length == 0 puts "ERROR: You must specify a path or URL to convert\n#{opt_parser}" exit end art = AsciiArt.new(ARGV[0]) art.image_chars = art.image_chars.reverse if invert_chars puts art.to_ascii_art(options) asciiart-0.0.10/asciiart.gemspec0000644000004100000410000000167014010032761016561 0ustar www-datawww-data# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'asciiart/version' Gem::Specification.new do |gem| gem.name = "asciiart" gem.version = AsciiArt::VERSION gem.authors = ["nodanaonlyzuul", "rosscooperman", "caderaspindrift"] gem.email = ["stephen@eastmedia.com"] # gem.description = %q{A command line tool to turn images into ASCII art} gem.summary = %q{A command line tool to turn images into ASCII art} gem.homepage = "https://github.com/nodanaonlyzuul/asciiart" gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] gem.add_dependency('rmagick', '2.13.4') gem.add_dependency('rainbow', '2.0.0') gem.add_development_dependency('pry') end asciiart-0.0.10/.gitignore0000644000004100000410000000026214010032761015401 0ustar www-datawww-data*.gem *.rbc .bundle .config .redcar .rvmrc .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp .DS_Storeasciiart-0.0.10/Rakefile0000644000004100000410000000003414010032761015053 0ustar www-datawww-datarequire "bundler/gem_tasks" asciiart-0.0.10/lib/0000755000004100000410000000000014010032761014157 5ustar www-datawww-dataasciiart-0.0.10/lib/asciiart/0000755000004100000410000000000014010032761015756 5ustar www-datawww-dataasciiart-0.0.10/lib/asciiart/version.rb0000644000004100000410000000005014010032761017763 0ustar www-datawww-dataclass AsciiArt VERSION = "0.0.10" end asciiart-0.0.10/lib/asciiart.rb0000644000004100000410000000510714010032761016306 0ustar www-datawww-datarequire "asciiart/version" require 'rmagick' require 'uri' require 'open-uri' require 'rainbow' require 'rainbow/ext/string' class AsciiArt attr_writer :image_chars def initialize(path_to_file) # open-uri open will fallback to IO open open(path_to_file) { |file| @data = file.read } self end def to_ascii_art(options = {}) options = { width: 100, color: false, format: "text" }.merge(options) img = Magick::Image.from_blob(@data).first width = options[:width] scale = (width.to_f / img.columns) height = ((img.rows * scale) / 2).to_i img.resize!(width, height) color_image = img.dup if options[:color] img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i image_chars.map! {|char| char == " " ? " " : char } if options[:format] == "html" border = "+#{'-' * width}+#{line_break(options[:format])}" border = html_char(border) if options[:format] == "html" output = border.dup img.view(0, 0, width, height) do |view| height.times do |i| output << '|' width.times do |j| character = image_chars[view[i][j].red/quantum_calc] if options[:format] == "html" if (options[:color]) pix = color_image.pixel_color(j,i) color_string = "color: #{pix.to_color( Magick::AllCompliance,false,8, true)};" else color_string = "" end character = html_char(character, color_string) else # text-format if options[:color] pix = color_image.pixel_color(j,i) character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue)) end end output << character end output << "|#{line_break(options[:format])}" end end output + border end def image_chars @image_chars ||= ' .~:+=o*x^%#@$MW'.chars.to_a end def inspect "#<#{self.class.to_s}>" end private def line_break(format) (format == "text") ? "\n" : "
" end def unified_rgb_value(number) if defined?(Magick::QuantumDepth) return (Magick::QuantumDepth == 16) ? (number / 256) : number else return (Magick::QuantumRange == 65535) ? (number / 256) : number end end def html_char(char, additional_style = "") "#{char}" end end asciiart-0.0.10/Gemfile0000644000004100000410000000011314010032761014677 0ustar www-datawww-datasource 'https://rubygems.org' # List gem dependencies in gemspec gemspec asciiart-0.0.10/LICENSE.txt0000644000004100000410000000205114010032761015232 0ustar www-datawww-dataCopyright (c) 2013 Eastmedia MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.