Skip to content

Instantly share code, notes, and snippets.

@yohfee
Created March 30, 2011 01:59
Show Gist options
  • Select an option

  • Save yohfee/893728 to your computer and use it in GitHub Desktop.

Select an option

Save yohfee/893728 to your computer and use it in GitHub Desktop.
~/.earthquake/plugin/image.rb
#coding: utf-8
require 'open-uri'
require 'RMagick'
Earthquake.init do
command :image do |m|
url = m[1]
blob = open(url).read
image = Magick::Image.from_blob(blob).shift
(0..image.rows).each do |y|
line = (0..image.columns).map do |x|
p = image.pixel_color(x, y)
r = (p.red * 6.0 / 256 / 256).to_i * 36
g = (p.green * 6.0 / 256 / 256).to_i * 6
b = (p.blue * 6.0 / 256 / 256).to_i * 1
c = 16 + r + g + b
"\e[48;5;#{c}m \e[m"
end.join
puts line
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment