Skip to content

Instantly share code, notes, and snippets.

@JohnMorales
Last active April 26, 2020 02:10
Show Gist options
  • Save JohnMorales/ddbd93820afbf83522b7 to your computer and use it in GitHub Desktop.
Save JohnMorales/ddbd93820afbf83522b7 to your computer and use it in GitHub Desktop.
ruby loco hack night project to convert an image to ascii art
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
source "https://rubygems.org"
gem 'pry'
# gem "ascii-image"
gem "rmagick", "=2.13.1"
gem "rainbow", "= 1.1.4"
gem "pry-rescue"
gem "paint"
@JohnMorales
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment