select exif metadata
[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                 join(' ', '',
12                         $exif->{YCbCrSubSampling} // (),
13                         $exif->{Interlace} // (),
14                         $exif->{Compression} // $exif->{FileType},
15                         $exif->{SVGVersion} // $exif->{PDFVersion} // (),
16                 ),
17                 $exif->{ColorType} ? " $exif->{BitDepth}bpp $exif->{ColorType}" : (),
18                 sprintf(' exif x%d', scalar %{$exif}),
19                 $exif->{Thumb} ? " thumb $exif->{ThumbnailLength}B" : (),
20                 (map " @ $_",
21                         $exif->{DateCreated} //
22                         $exif->{CircaDateCreated} //
23                         $exif->{ModifyDate} //
24                         $exif->{ZipModifyDate} //
25                         (),
26                 ),
27                 $exif->{GPSPosition} ?  " $exif->{GPSPosition}" =~ s/ deg/./gr :
28                 $exif->{Location} ? " $exif->{Location}" : (),
29                 $exif->{GPSAltitude} ? " $exif->{GPSAltitude}" : (),
30                 (map " hw $_", join(' ',
31                         $exif->{Make} // (), $exif->{Model} // (),
32                         $exif->{FOV} ? "(FOV $exif->{FOV})" : (),
33                 ) || ()),
34                 (map " sw $_", $exif->{Software} // $exif->{Application} // ()),
35                 (map " > $_", $exif->{'Description-nl'} // ()),
36                 $exif->{Warning} ? " ! $exif->{Warning}" : (),
37         );
38 } or warn $@;
39
40 open my $pgm, '-|', convert => (
41         -compress => 'none',
42         '+distort' => SRT => '0,0 1,.56 0',
43         -thumbnail => $size || '66x23',
44         $file => 'pgm:-'
45 ) or die $!;
46 <$pgm> eq "P2\n" or do {
47         say for @info;
48         exit 1;
49 };
50 <$pgm>; <$pgm>;  # ignore depth, dimensions
51
52 my @ch = split //, " .:coO@";
53 while (<$pgm>) {
54         print $ch[ $_ * @ch >> 8 ] for /\d+/g;
55         print $info[$. - 4], $/;
56 }