summarise file type and dimensions
[minime.git] / termimg
1 #!/usr/bin/perl
2 use 5.014;
3 my ($file, $size) = @ARGV;
4
5 my @info = eval {
6         require Image::ExifTool;
7         my $exif = Image::ExifTool->new->ImageInfo($file);
8         return (
9                 " $exif->{MIMEType}",
10                 $exif->{ImageSize} ? " $exif->{ImageSize} ($exif->{Megapixels}MP)" : (),
11                 $exif->{ColorType} ? " $exif->{BitDepth}bpp $exif->{ColorType}" : (),
12         );
13 } or warn $@;
14
15 open my $pgm, '-|', convert => (
16         -compress => 'none',
17         '+distort' => SRT => '0,0 1,.56 0',
18         -thumbnail => $size || '66x23',
19         $file => 'pgm:-'
20 ) or die $!;
21 <$pgm> eq "P2\n" or do {
22         say for @info;
23         exit 1;
24 };
25 <$pgm>; <$pgm>;  # ignore depth, dimensions
26
27 my @ch = split //, " .:coO@";
28 while (<$pgm>) {
29         print $ch[ $_ * @ch >> 8 ] for /\d+/g;
30         print $info[$. - 4], $/;
31 }