# $Id: inlineimage.rb,v 1.5 2003/12/10 16:42:14 not Exp $
#2003/12/27 修正
=begin
イメージの貼り付け
サイズを省略すると自動取得を試みる
縦横@inlineimage_max_size(=200)以下への自動縮尺を行う
「-nonet」オプションでネット不接続
標準で JPEG, PNG, GIF 対応
[RAA:image_size]があると PCX, PSD, XPM, TIFF, XBM, PGM, PBM, PPM, BMP, SWF
あたりにも対応
class(=@inlineimage_class.keys)指定のdivタグ囲み対応(pタグ処理済)
サムネイル画像(=@thumb/同名ファイル)対応
サムネイル画像が有ればそれを提示
サムネイル画像が無ければ画像のサイズを縮小して提示
画像サイズが@inlineimage_max_sizeより大きいならなら画像へのリンク
サムネイル画像やリンク無しの指定可能
usage:
image([file or url] [title|alt] [width]x[height] [align or class])
ndiary.conf内でクラス指定可能
CLASS_IMAGE = {'photoimage'=>'photoclass'}
ndiary.conf内で画像リストファイル生成指定可能
INLINE_IMAGEFILE = true
example:
image(../img/foo.jpg bar)
->
# thumb/foo.jpgのサイズ取得+縦横100以下に縮尺
->
# thumb/foo.jpgが無い場合
->
# thumb/foo.jpgが無く、foo.jpgのサイズが縦横100以下の場合
image(../img/foo.jpg link|bar 120x40 right)
->
image(../img/foo.jpg| bar 200x150 imgsmall)
->

' unless div.nil?
img
}
# 自分でつけてもらった方がいいか?
#if align.to_s.downcase == 'right' and /
$/ !~ str then
# str.replace(str + '
')
#end
when :AFTER_P #divタグ追加によるpタグの皺寄せ(内容の無いpタグ)除去
# str.gsub!(/
\s*<\/p>/mi, '') str.gsub!(/
\s*<\/p>/mi, "\n") str.gsub!(/
\s*
\s*<\/p>/mi, "\n")
when :HTML
if @diary.kind_of?(PastDiary) && flag_imagefiles
imagefile_write(@diary.date[0..5]) #bookstore_x内で定義
end
end
end
def get_stream(url, proxy) #open-uriでproxy含めてうまく行ったら不要
if /^http/ !~ url # fileなら読み出す
$stderr.puts "CHK; access; #{url}"
return open(url, "rb")
end
return if @diary.config['nonet']
$stderr.puts "CHK; access; #{url}"
require 'net/http'# urlならダウンロード
domain, port = "", ""
if url =~ /\/\/(.+?)(?:\/|$)/
domain = $1.to_s
end
protocol = url.split(":").first + "://"
path = url.gsub(Regexp.new(protocol + domain),"")
proxy = port = nil
if proxy
proxy, port = proxy.split(':')
port = port.to_i
end
begin
http = Net::HTTP::Proxy(proxy, port).new(domain, 80)
if /1\.6/ =~ RUBY_VERSION
file_info, = http.get2(path)
else
file_info = http.get(path)
end
if file_info.code == '302'
path = file_info.header['location'].sub(Regexp.new(url), "")
file_info = http.get(path)
end
return(file_info.response.body)
rescue
# return $!
return nil
end
end
def anchor_link #imagefiles-list生成用
anchor = ''
if @diary.paragraphAnchor
if @diary.anchorEachTopic
anchor = "_t#{@diary.instance_eval{@cntTopic}}_#{@diary.instance_eval{@cntParagraph + 1}}"
else
anchor = "_#{@diary.instance_eval{@cntParagraph + 1}}"
end
end
return anchor
end
end