Skip to content

Instantly share code, notes, and snippets.

@squm
Created May 17, 2016 06:24
Show Gist options
  • Save squm/6db00282cdf15a76026e3a05333f28f6 to your computer and use it in GitHub Desktop.
Save squm/6db00282cdf15a76026e3a05333f28f6 to your computer and use it in GitHub Desktop.
sub identify {
my $file = shift;
return unless (-e $file);
$_ = `$I $file` if (-e $file);
# debug
# $_ = '1.JPG JPEG 2048x1536 2048x1536+2222+3333 8-bit sRGB 912KB 0.000u 0:00.000';
my @param = split /\s+/;
$file = shift @param;
pop @param;
pop @param;
# JPEG 2048x1536 2048x1536+2222+3333 8-bit sRGB 912KB
my @width = (
1 , # JPEG
4 * 2 + 1 , # 2048x1536
4 * 4 + 3 , # 2048x1536+2222+3333
2 + 4 , # 8-bit
5 , # sRGB
8 , # 912KB
);
my @sprintf = map {
my $w = shift @width;
sprintf '%' . $w . 's', $_;
} @param;
my $width_file = 80 - length "@sprintf";
# debug
# $file = '12' x $width_file;
my $ellipsis = '...';
my $is_ellipsis = length $file > $width_file;
$file =
join '', $ellipsis, (split //, $file)
[
length($file) - $width_file + length($ellipsis) ..
length($file) - 1
]
if ($is_ellipsis);
printf "%-${width_file}s @sprintf\n", $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment