-
-
Save emdeeeks/5e86bef78ac910f56d1f43027ad47cd1 to your computer and use it in GitHub Desktop.
ruby loco hack night project to convert an image to ascii art
This file contains hidden or 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 hidden or 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