#!/usr/bin/perl
$layer
=(
shift
,
shift
)
if
$ARGV
[0] =~ /^-(l|-?layer)$/;
if
(
@ARGV
>1) {
print
"Usage: xcftopnm [-layer N] [xcffile]\n"
;
exit
(1);
}
$tmpfile
=
"xcftopnm$$~"
;
END {
unlink
$tmpfile
}
if
(
@ARGV
==0) {
my
$buff
;
open
TMP,
">$tmpfile"
or
die
"Unable to open temporary file '$tmpfile' for writing: $!\n"
;
binmode
STDIN;
binmode
TMP;
print
TMP
$buff
while
sysread
STDIN,
$buff
,16384;
close
TMP;
@ARGV
=
$tmpfile
;
}
Gimp::init(
"spawn/no-data"
);
$image
= Gimp->xcf_load(0,(
$ARGV
[0])x2);
$layer
=
defined
$layer
? (
$image
->get_layers)[
$layer
] :
$image
->flatten;
$layer
->file_pnm_save((
$tmpfile
)x2,1);
Gimp::deinit;
open
TMP,
"<$tmpfile"
or
die
"Unable to open temporary file '$tmpfile' for reading: $!\n"
;
binmode
STDOUT;
binmode
TMP;
print
STDOUT
$buff
while
sysread
TMP,
$buff
,16384;
close
TMP;