Created
August 2, 2010 03:09
-
-
Save ultraist/504059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# ターミナル内で画像を表示するコマンド | |
# sshで作業しているときに謎の画像ファイルを確認したいけどいろいろメンドイときに便利. | |
# | |
# 仕様: 指定された画像をImagerでpnmに変換してaviewで表示するだけ. | |
# aviewを使用しているのでapt-get install aviewなどでインストールする. | |
# png,jpeg,gif等を読みたい場合にはImagerをインストールする前にlibpng-dev等を入れておく. | |
# | |
# スクリーンショット: http://www.udp.jp/g/10s.png http://www.udp.jp/g/m8.png | |
use strict; | |
use warnings; | |
use Imager; | |
use File::Temp; | |
my @AA_OPTIONS = qw/-reverse/; | |
my $file = shift; | |
$file or die "usage: $0 image\n"; | |
my $im = Imager->new(); | |
unless ($im->read(file => $file)) { | |
die "$0: $file: " . $im->errstr . "\n"; | |
} | |
my $tempfile = File::Temp->new(UNLINK => 1, SUFFIX => '.pnm'); | |
binmode($tempfile); | |
unless ($im->write(fd => fileno($tempfile), type => "pnm")) { | |
die "$0: " . $im->errstr . "\n"; | |
} | |
my $pid = fork(); | |
unless (defined($pid)) { | |
die "$0: fork: $!\n"; | |
} | |
if ($pid) { | |
wait; | |
} else { | |
push(@AA_OPTIONS, $tempfile); | |
exec("aview", @AA_OPTIONS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment