Ctrl+A 画像を w3m で見るための local-cgi (id:yshl:20060428:1146248672) 続き

前の local-cgi では画像を選択した時の青い網まで再現していたので、全体が青みがかったり画像がちらついたりする。なので青い網は無しの方向で修正。
ついでに読み込む画像をカーソル位置にある画像からリンク先にある画像に変更。前者は「リンクと画像の一覧」でリンクにすることができるので。

#!/usr/bin/perl -w
# .w3m/keymap に
# keymap 適当なキー GOTO file:///cgi-bin/このcgiの名前
# を加える
use strict;
use Image::Magick;

my $url = $ENV{W3M_CURRENT_LINK};
my $file="/tmp/w3mctrla$$";
system("/usr/bin/w3m -dump_source $url > $file");

my $image1 = Image::Magick->new;
my $image2 = Image::Magick->new;
my $mask = Image::Magick->new(size=>'2x2');
$image1->Read($file);
$image2->Read($file);
$mask->ReadImage('xc:black');
$mask->Draw(primitive=>'line', points=>'0,1 1,0', stroke=>'white',strokewidth=>0.1,antialias=>'false');
print "$image1\n";
$image1->Composite(image=>$mask, compose=>'Multiply', tile=>'True');
$image2->Composite(image=>$mask, compose=>'Multiply', tile=>'True');
$image1->Composite(image=>$image2, compose=>'Add', y=>1);

print "Content-type: image/png\n\n";
binmode STDOUT;
$image1->Write('png:-');


undef $image1;
undef $image2;
undef $mask;
unlink($file);
exit;