ruby loco hack night project to convert an image to ascii art
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rmagick' | |
require 'paint' | |
unless File.exists? './o-AMERICAN-FLAG-facebook.jpg' | |
`curl -O http://i.huffpost.com/gen/1649894/images/o-AMERICAN-FLAG-facebook.jpg` | |
end | |
resource = open('./o-AMERICAN-FLAG-facebook.jpg') | |
image = Magick::ImageList.new | |
image.from_blob resource.read | |
image = image.scale(150 / image.columns.to_f) | |
image = image.scale(image.columns, image.rows / 1.7) | |
cur_row = 0 | |
image.each_pixel do |pixel, col, row| | |
color = pixel.to_color(Magick::AllCompliance, false, 8) | |
if cur_row != row | |
puts | |
cur_row = row | |
end | |
print Paint[' ', '', color] | |
end | |
puts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem 'pry' | |
# gem "ascii-image" | |
gem "rmagick", "=2.13.1" | |
gem "rainbow", "= 1.1.4" | |
gem "pry-rescue" | |
gem "paint" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here's the image I used:
http://i.huffpost.com/gen/1649894/images/o-AMERICAN-FLAG-facebook.jpg