pax_global_header00006660000000000000000000000064142506575430014525gustar00rootroot0000000000000052 comment=d97f3b81b55135e8f6aec7add31218595482bcc1 asciiart-0.3.0/000077500000000000000000000000001425065754300133245ustar00rootroot00000000000000asciiart-0.3.0/.gitignore000066400000000000000000000002621425065754300153140ustar00rootroot00000000000000*.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.3.0/CHANGELOG.md000066400000000000000000000023151425065754300151360ustar00rootroot00000000000000# Asciiart changelog Asciiart follows [Semantic Versioning](https://semver.org/), please see the [README.md](README.md) for details. ## 0.3.0 ### Fixed * Ruby 3.1.x compatibility [#13](https://github.com/nodanaonlyzuul/asciiart/issues/13) ### (semi) Tested Ruby Versions I hope to have a better automated test matrix in the future but... * ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20] * ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20] * ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin20] ## 0.2.0 ### Notes #### Rehabilitation & being a better citizen This gem started as a fast-and-loose side project in 2014. It mostly worked for many years, with no need for major updates. In January 2022, I noticed a lot of the gem & its dependencies' syntax didn't play well in modern versions of Ruby. #### Tagging & Github Releases This is the version where I started caring about using tags & GH releases. ### Fixed * Fixing ability to open a URL via cli.[[#12](https://github.com/nodanaonlyzuul/asciiart/pull/12)] * Fixing color output issues.[[#12](https://github.com/nodanaonlyzuul/asciiart/pull/12)] ## < 0.2.0 These were the dark ages. I'm sorry. asciiart-0.3.0/Gemfile000066400000000000000000000001131425065754300146120ustar00rootroot00000000000000source 'https://rubygems.org' # List gem dependencies in gemspec gemspec asciiart-0.3.0/LICENSE.txt000066400000000000000000000020511425065754300151450ustar00rootroot00000000000000Copyright (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.asciiart-0.3.0/README.md000066400000000000000000000246221425065754300146110ustar00rootroot00000000000000# 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.3.0/Rakefile000066400000000000000000000000341425065754300147660ustar00rootroot00000000000000require "bundler/gem_tasks" asciiart-0.3.0/asciiart.gemspec000066400000000000000000000017041425065754300164720ustar00rootroot00000000000000# -*- 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", "wendy0402"] 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', '4.2.4') gem.add_dependency('rainbow', '3.0.0') gem.add_development_dependency('pry') end asciiart-0.3.0/bin/000077500000000000000000000000001425065754300140745ustar00rootroot00000000000000asciiart-0.3.0/bin/asciiart000077500000000000000000000024731425065754300156270ustar00rootroot00000000000000#!/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.3.0/lib/000077500000000000000000000000001425065754300140725ustar00rootroot00000000000000asciiart-0.3.0/lib/asciiart.rb000066400000000000000000000013411425065754300162150ustar00rootroot00000000000000require "asciiart/version" require 'rmagick' require 'uri' require 'open-uri' require 'rainbow' require 'rainbow/ext/string' require File.expand_path("../asciiart/html", __FILE__) require File.expand_path("../asciiart/text", __FILE__) class AsciiArt attr_writer :image_chars def initialize(path_to_file) # open-uri open will fallback to IO open URI.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 renderer = (options[:format] == "text" ? AsciiRenderer::Text.new(img) : AsciiRenderer::Html.new(img)) renderer.to_ascii_art(options) end end asciiart-0.3.0/lib/asciiart/000077500000000000000000000000001425065754300156715ustar00rootroot00000000000000asciiart-0.3.0/lib/asciiart/html.rb000066400000000000000000000031231425065754300171610ustar00rootroot00000000000000module AsciiRenderer class Html def initialize(img) @img = img @quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i end def to_ascii_art(options = {}) width = options[:width] scale = (width.to_f / @img.columns) height = ((@img.rows * scale) / 2).to_i img = @img.resize(width, height) @color_img = img.dup if options[:color] img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize border = "+#{'-' * width}+
" border = html_char(border) output = border.dup img.view(0, 0, width, height) do |view| height.times do |i| output << '|' width.times { |j| output << pixel_to_char(view, j: j, i: i, color: options[:color]) } output << "|
" end end output + border end def pixel_to_char(view, args = {}) pixel = view[args[:i]][args[:j]] character = image_chars[pixel.red/@quantum_calc] if (args[:color]) pix = @color_img.pixel_color(args[:j],args[:i]) color_string = "color: #{pix.to_color( Magick::AllCompliance,false,8, true)};" else color_string = "" end html_char(character, color_string) end def image_chars @image_chars ||= " .~:+=o*x^%\#@$WQ".chars.to_a.map{ |char| char == " " ? " " : char} end private def html_char(char, additional_style = "") "#{char}" end end endasciiart-0.3.0/lib/asciiart/text.rb000066400000000000000000000031241425065754300172020ustar00rootroot00000000000000module AsciiRenderer class Text def initialize(img) @img = img @quantum_calc = Magick::QuantumRange / Magick::QuantumPixel.to_i end def to_ascii_art(options = {}) width = options[:width] scale = (width.to_f / @img.columns) height = ((@img.rows * scale) / 2).to_i img = @img.resize(width, height) @colored_img = img.dup if options[:color] img = img.quantize(image_chars.length, Magick::GRAYColorspace).normalize border = "+#{'-' * width}+\n" output = border.dup img.view(0, 0, width, height) do |view| height.times do |i| output << '|' width.times { |j| output << pixel_to_char(view,j: j , i: i, color: options[:color] ) } output << "|\n" end end output + border end def pixel_to_char(view, args = {}) pixel = view[args[:i]][args[:j]] character = image_chars[pixel.red/@quantum_calc] if args[:color] pix = @colored_img.pixel_color(args[:j],args[:i]) character = character.color(unified_rgb_value(pix.red), unified_rgb_value(pix.green), unified_rgb_value(pix.blue)) end character end def image_chars @image_chars ||= " .~:+=o*x^%\#@$WQ".chars.to_a end private def unified_rgb_value(number) if defined?(Magick::QuantumDepth) num = (Magick::QuantumDepth == 16) ? (number / 256) : number else num = (Magick::QuantumRange == 65535) ? (number / 256) : number end (num > 255) ? 255 : num end end end asciiart-0.3.0/lib/asciiart/version.rb000066400000000000000000000000471425065754300177040ustar00rootroot00000000000000class AsciiArt VERSION = "0.3.0" end