1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
package URI::Title::Image;
$URI::Title::Image::VERSION = '1.904';
use warnings;
use strict;
use Image::Size;
sub types {(
'image/gif',
'image/jpg',
'image/jpeg',
'image/png',
'image/x-png',
)}
sub pnginfo {
my ($data_ref) = @_;
my ($x, $y, $title) = (0, 0, '');
if ( eval { require Image::ExifTool } ) {
my $info = Image::ExifTool::ImageInfo($data_ref);
($x, $y, $title) = ($info->{ImageWidth}, $info->{ImageHeight}, $info->{Title});
}
elsif( eval { require Image::PNG::Libpng } ) {
my $png = Image::PNG::Libpng::read_from_scalar($$data_ref);
$x = $png->get_image_width();
$y = $png->get_image_height();
my $text_chunks = $png->get_text();
for (@$text_chunks) {
if ($_->{key} eq "Title") {
$title = $_->{text};
last;
}
}
}
else {
($x, $y) = imgsize($data_ref);
}
return ($x, $y, $title);
}
sub title {
my ($class, $url, $data, $type) = @_;
$type =~ s!^[^/]*/!!;
$type =~ s!^x-!!;
my $title = "";
my $x = 0;
my $y = 0;
if ( $type =~ /png/ ) {
($x, $y, $title) = pnginfo(\$data);
}
else {
($x, $y) = imgsize(\$data);
}
$title ||= ( split m{/}, $url )[-1];
return $x && $y
? "$title ($type ${x}x${y})"
: "$title ($type)";
}
1;
__END__
=for Pod::Coverage::TrustPod types title pnginfo
=head1 NAME
URI::Title::Image - get titles of images
=head1 VERSION
version 1.904
=cut
|