Skip to content

Instantly share code, notes, and snippets.

@no6v
Forked from jugyo/aview.rb
Created March 22, 2012 12:54
Show Gist options
  • Save no6v/2158140 to your computer and use it in GitHub Desktop.
Save no6v/2158140 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 File.exist?(m[1]) or 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