# $Id: inlineimage.rb,v 1.3 2003/08/21 12:38:37 not Exp $ # 2003/10/01 微修正(一歩さん) # 2003/10/02 リモート画像の高さと幅をゲットするようにした(waka) =begin 以下は一歩さんオリジナルコメント(waka) イメージの貼り付け。サイズを省略したとき、ローカルのファイルだったときは 自動取得を試みる。その際画像サイズの自動縮尺(縦横100=@max_size以下)を行う。 画像サイズ取得ライブラリの変更。(うちでは不具合が発生した為) 画像へのリンク張り付け。 alignに渡る引数がimgsmall,imglargeの場合、
で囲んだ上で 「」「
」を除去してしまう。 usage: image(../img/foo.jpg foo 120x40 right) ->
#自動サイズ取得+縦横が100以下になるよう縮尺
reference:
アサノさん http://www.mushline.com/junk/200309.html#d27_t2
猫旦那さん http://aturust.com/topics/200309.html#26_t1
=end
class Filter
def getFileStream(url,proxy)
require 'net/http'
if /^http/ =~ url then
domain = ""
port = ""
if url =~ /\/\/(.+?)(?:\/|$)/ then
domain = $1.to_s
end
protocol = url.split(":").first + "://"
path = url.gsub(Regexp.new(protocol + domain),"")
if proxy then
proxy, port = proxy.split(':')
port = port.to_i
else
proxy = port = nil
end
begin
http = Net::HTTP::Proxy(proxy,port).new(domain,80)
if /1\.6/ =~ RUBY_VERSION then
file_info, = http.get2(path)
else
file_info = http.get(path)
end
if file_info.code == '302' then
path = file_info.header['location'].sub(Regexp.new(url), "")
file_info = http.get(path)
end
return(file_info.response.body)
rescue
return $!
end
else
open(url, "rb") do |fh|
fh.read
end
end
end
def inlineimage_ex(str, type)
require 'image_size'
case type
when :P
proxy = nil
if @diary.respond_to?('config') then
proxy = @diary.config['PROXY']
end
align = ''
str.gsub!(/image\(((?:https?:|\.).+?)\)/i){
url, alt, size, align = $1.split(/ /)
#img = %Q!/,'') str.gsub!(/<\/p>/,'') end str end end end