2 # $Id: add-extent.pl,v 1.3 2003/08/25 11:50:33 yto Exp $
3 # HTML ¤Î img ¥¿¥°¤Ë width ¤È height ¤ò¤¹
9 my $IDENTIFY = `which identify`;
10 die "NO identify!" unless ($IDENTIFY =~ /identify$/);
15 usage
: prog
<file
> [file
]...
20 for my $fname (@ARGV) {
22 # HTML ¥Õ¥¡¥¤¥ë¤ò°ìµ¤¤ËÆɤ߹þ¤à
23 open(IN
, $fname) or die;
24 my $all = join('', <IN
>);
29 $cfn =~ s!/[^/]*$!!; # ¥Ñ¥¹
30 $cfn .= "/cache_extent-info";
32 my $file_info_update_flag = 0;
35 next if (/^\#/ or /^\s*$/);
38 $file_info{$c[0]} = [@c[1..2]];
44 # img ¥¿¥°¤ÎÉôʬ¤ò¼è¤ê¤À¤¹¡£
45 my @con = split(/(<img.+?>)/ims, $all);
47 next if (scalar(@con) == 1); # img ¥¿¥°¤¬Ìµ¤¤¥Õ¥¡¥¤¥ë¤Ï²¿¤â¤·¤Ê¤¤
50 for (my $i = 0; $i < @con; $i++) {
52 if ($con[$i] =~ /^(<img.+?>)/ims) {
55 # width ¤È height ¤ÎξÊý¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ï²¿¤â¤·¤Ê¤¤
56 next if ($in =~ /\W((width|height)\W.+?\W){2}/i); # ad hoc
58 # width or height ¤ò¾Ã¤¹
59 $con[$i] =~ s/\s+(width|height)=[^\s]+//gims;
61 # ²èÁü¥Õ¥¡¥¤¥ë̾¤ò¼è¤ê½Ð¤¹
62 die unless ($in =~ /\ssrc="?(\S+?)"?[\s>]/i);
65 # identify ¤Ç width ¤È height ¤ò¼èÆÀ
66 next unless (-e
$imgfn);
68 if (defined $file_info{$imgfn}) {
69 ($w, $h) = @
{$file_info{$imgfn}};
71 ($w, $h) = (`$IDENTIFY $imgfn` =~ /(\d+)x(\d+)/);
72 $file_info{$imgfn} = [$w, $h];
73 $file_info_update_flag = 1;
74 # print join("----", @{$file_info{$imgfn}}),"\n";
78 # img ¥¿¥°Æâ¤Ë width ¤È height ¤òÄɲÃ
79 $con[$i] =~ s
|>$| width
="$w" height
="$h">|ims
;
83 # cache ¥Õ¥¡¥¤¥ë¤Î½ñ¤¹þ¤ß
84 if ($file_info_update_flag and open(F
, "> $cfn")) {
85 foreach my $f (sort keys %file_info) {
86 print F
"$f @{$file_info{$f}}\n";
92 next if ($num == 0); # Êѹ¹²Õ½ê¤Ê¤·
94 # Êѹ¹²Õ½ê¤¬¤¢¤Ã¤¿¤é¡¢¸µ¤Î¥Õ¥¡¥¤¥ë¤òÂàÈò¤·¤Æ¤«¤é¡¢¾å½ñ¤¤¹¤ë
95 copy
($fname, "$fname.bak") or die;
96 open(OUT
, "> $fname") or die;
97 print OUT
join("", @con);