From ec2421cd86c78acdeae1c06144a31d5119a2d9e1 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 9 Feb 2020 22:01:17 +0100 Subject: [PATCH] summarise file type and dimensions --- termimg | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/termimg b/termimg index 4deee15..bec4a4b 100755 --- a/termimg +++ b/termimg @@ -2,17 +2,30 @@ use 5.014; my ($file, $size) = @ARGV; +my @info = eval { + require Image::ExifTool; + my $exif = Image::ExifTool->new->ImageInfo($file); + return ( + " $exif->{MIMEType}", + $exif->{ImageSize} ? " $exif->{ImageSize} ($exif->{Megapixels}MP)" : (), + $exif->{ColorType} ? " $exif->{BitDepth}bpp $exif->{ColorType}" : (), + ); +} or warn $@; + open my $pgm, '-|', convert => ( -compress => 'none', '+distort' => SRT => '0,0 1,.56 0', -thumbnail => $size || '66x23', $file => 'pgm:-' ) or die $!; -<$pgm> eq "P2\n" or die "ascii pgm input required\n"; +<$pgm> eq "P2\n" or do { + say for @info; + exit 1; +}; <$pgm>; <$pgm>; # ignore depth, dimensions my @ch = split //, " .:coO@"; while (<$pgm>) { print $ch[ $_ * @ch >> 8 ] for /\d+/g; - print $/; + print $info[$. - 4], $/; } -- 2.30.0