ITeye博客

自制小工具 一键贴图

open2ye · 2010-07-07 21:23 · Ruby · 编程语言 · PHP · EXT · Ruby · Flash · rubygems · Markdown

鼠标右单击即可上传图片

地址要短

要直接到剪贴板


require 'rubygems'
require "win32/clipboard"
include Win32

$filename = ARGV[0]
TYPES = %w{.jpg .gif .png .jpeg}

def upload_file(file)
  puts "Your want to upload file #{$filename}"
  cmd = "curl -s -F Filedata=@\"#{$filename}\" -F Filename=\"#{File.basename(file)}\" -F Upload=\"Submit Query\" tu.6.cn/flash/index/tu_user_temp/-5073549"
  res = `#{cmd}`
  res =~ /(.+?):::/
  $1
end

def file_ext_allow?(file)
  TYPES.include?(File.extname(file).downcase)
end

def short_url(url)
  cmd = "curl -s http://tinyurl.com/api-create.php?url=#{url}"
  `#{cmd}`
end

if File.exists?($filename) && file_ext_allow?($filename)
  url = upload_file(ARGV[0])
  url = short_url(url)
  Clipboard.set_data(url)
  puts url
  puts "Tt is in you clipboard"
else
  puts "File not exist / File is ext name must in #{TYPES.join(",")}"
end

在 http://gist.github.com/466673

可惜 javaeye 不能贴 gist

评论(3)

  1. #3 楼 · mewleo · 2010-07-14 14:57

    open2ye writes:

    自己要搞个 curl.exe

    搞个弹出框,可以添加tag比较好吧。 支持一下,挺有趣的。

  2. #2 楼 · open2ye · 2010-07-13 10:50

    有人问 怎么做成右单击

    写个bat publish.bat

    
    c:\Ruby187\bin\ruby.exe C:\tools\upload_file.rb %1
    
    

    添加右单击按钮

  3. #1 楼 · open2ye · 2010-07-07 21:25

    自己要搞个 curl.exe

评论功能维护中,当前仅展示历史评论。