Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created March 22, 2012 05:04
Show Gist options
  • Save jugyo/2156204 to your computer and use it in GitHub Desktop.
Save jugyo/2156204 to your computer and use it in GitHub Desktop.
aview earthquake.gem plugin
# coding: UTF-8
require 'open-uri'
require 'tmpdir'
Earthquake.init do
command :aview do |m|
if m[1] =~ /^http/
url = m[1]
else
url = twitter.show(m[1])["profile_image_url"]
end
Dir.mktmpdir do |dir|
source = File.join(dir, File.basename(url))
dest = File.join(dir, 'dest.pnm')
File.open(source, 'wb') {|f| f << open(url).read}
begin
(system 'convert', source, dest) || (raise 'Faild to execute `convert`. Please install ImageMagick.')
(system 'aview', '-driver', 'curses', dest) || (raise 'Faild to execute `aview`. Please install Aview.')
rescue => e
puts e.message
end
end
end
help :aview, "Show image as text using Aview", <<-HELP
⚡ :aview http://example.com/image.jpg
⚡ :aview jugyo
HELP
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment