Browse Subversion Repository
Contents of /script/imgUpdate.rb
Parent Directory
| Revision Log
Revision 366 -
( show annotations)
( download)
Fri May 9 11:33:40 2008 UTC
(16 years ago)
by satofumi
File size: 811 byte(s)
adjust for fullscreen
| 1 |
#!/usr/bin/ruby |
| 2 |
# <img src="file" における、file 画像のサイズを width, height に反映させるスクリプト |
| 3 |
# Satofumi KAMIMURA |
| 4 |
|
| 5 |
|
| 6 |
def updateTag(image_file, other_tag, basedir) |
| 7 |
|
| 8 |
file = basedir + '/' + image_file |
| 9 |
if `image_size #{file}`[/ ([0-9]+)x([0-9]+)/] |
| 10 |
width = $1 |
| 11 |
height = $2 |
| 12 |
end |
| 13 |
|
| 14 |
'<img src="' + image_file + '" width="' + width.to_s + '" height="' + height.to_s + '"' + other_tag + ">\n" |
| 15 |
end |
| 16 |
|
| 17 |
|
| 18 |
ARGV.each { |file| |
| 19 |
|
| 20 |
File.open(file) { |io| |
| 21 |
output_lines = ''; |
| 22 |
basedir = File.dirname(file) |
| 23 |
|
| 24 |
# <img タグを探して置換 |
| 25 |
while line = io.gets |
| 26 |
if line =~ /^<img src="(.+?)"(.+?)>$/ |
| 27 |
output_lines += updateTag($1, $2, basedir) |
| 28 |
else |
| 29 |
output_lines += line |
| 30 |
end |
| 31 |
end |
| 32 |
|
| 33 |
# ファイルの更新 |
| 34 |
File.open(file, 'w') { |io| |
| 35 |
io.write(output_lines) |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| |