Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby19
- # {{{ Unimportant
- module Scrshot
- # }}}
- #-------------------------------Configuration----------------------------------#
- # Where to save the screenshot
- Screenshot_Dir = File.join(ENV['HOME'], 'screenshots')
- # Default screenshot name
- Screenshot_Name = ARGV.first || 'currentdesk'
- # Default thumbnail extension (currentdesk becomes currentdeskt)
- Thumbnail_Extension = 't'
- # Thumbnail size
- Thumbnail_Size = '10%'
- # FTP info
- Hostname = ''
- Username = ''
- Password = ''
- Remote_Dir = ''
- #------------------------------------------------------------------------------#
- # {{{1 Unimportant
- class << self
- def get_filenames
- full_name = File.join(Screenshot_Dir, Screenshot_Name)
- thumb_name = full_name + Thumbnail_Extension
- return ["#{full_name}.png", "#{thumb_name}.png"]
- end
- end
- class Screeny
- def initialize
- take_screenshot(Screenshot_Name)
- create_thumbnail(Screenshot_Name, Thumbnail_Extension, Thumbnail_Size)
- upload_screenshot
- end
- private
- def take_screenshot(name)
- if File.directory?(Screenshot_Dir)
- full_name = File.join(Screenshot_Dir, name)
- system "import -window root #{full_name}.png"
- else
- raise "'#{Screenshot_Dir}' does not exist."
- end
- end
- def create_thumbnail(name, ext, pct)
- unless `which mogrify`.strip == ''
- full_name = File.join(Screenshot_Dir, name)
- thumb_name = full_name + ext
- system "cp #{full_name}.png #{thumb_name}.png"
- system "mogrify -resize #{pct} #{thumb_name}.png"
- else
- raise "'mogrify' command not found. is 'imagemagick' installed?"
- end
- end
- def upload_screenshot
- require 'net/ftp'
- ftp = Net::FTP.new(Hostname)
- ftp.login(user = Username, passwd = Password)
- ftp.chdir(Remote_Dir) unless Remote_Dir == ''
- Scrshot::get_filenames.each do |name|
- ftp.put(name, File.basename(name))
- end
- ftp.close
- end
- end
- end
- if __FILE__ == $0
- if %w[-h --help].include?(ARGV.first)
- puts "Usage: #{File.basename($0)} [name]"
- puts "[name] is optional"
- else
- Scrshot::Screeny.new
- end
- end
Add Comment
Please, Sign In to add comment