Media::DateTime::JPEG - A plugin for the C<Media::DateTime> module to support


Media-DateTime documentation Contained in the Media-DateTime distribution.

Index


Code Index:

NAME

Top

Media::DateTime::JPEG - A plugin for the Media::DateTime module to support JPEG files.

SYNOPSIS

Top

Media::DateTime::JPEG shouldn't be used directly. See Media::DateTime.

METHODs

Top

match

Takes a filename as an arguement. Used by the plugin system to determine if this plugin should be utilized for the file. Returns true if the filename ends in .jpeg or .jpg.

datetime

Takes a filename as an arguement and returns the creation date or a false value if we are unable to parse it.

SEE ALSO

Top

See Media::DateTime for usage. Image::Info is used to extract data from JPEG files.

AUTHOR

Top

Mark V. Grimes, <mgrimes@cpan.org<gt>

FUTURE PLANS

Top

May use a more flexible approach to assertaining if a file is a jpeg and might check that exif data exists in the match method.

COPYRIGHT AND LICENSE

Top


Media-DateTime documentation Contained in the Media-DateTime distribution.

package Media::DateTime::JPEG;

use strict;
use warnings;

use Carp;
use Image::ExifTool;
use DateTime;

our $VERSION = '0.30';
my $exifTool;

sub datetime {
	my ($self, $f) = @_;

	$exifTool = Image::ExifTool->new() unless $exifTool;
	$exifTool->ExtractInfo( $f ) or do {
		warn "Exiftool unable to read: $f\nFallback to file timestamp.\n";
		return;       
	};                  

	my $datetime = $exifTool->GetValue( 'DateTimeOriginal' );
	do {
		warn "JPEG does not contain DateTimeOriginal exif entry ($f),\nFallback to file timestamp.\n";
		return;
	} unless $datetime;


	# DateTime format = yyyy:mm:dd hh:mm:ss
	my ($y,$m,$d,$h,$min,$s) = $datetime =~ m/
												(\d{4})  :	# year
												(\d{2})  :  # month
												(\d{2})     # day
														\s		# space
												(\d{2})  :  # hour 
												(\d{2})  :  # min
												(\d{2})     # sec
										/x
		or die "failed DateTime pattern match in $f\n";

	my $date = DateTime->new(	year	=> $y,
								month	=> $m,
								day		=> $d,
		   						hour	=> $h,
								minute	=> $min,
								second	=> $s,
					) or die "couldnt create DateTime";

	return $date;
}

sub match { 
	my ($self,$f) = @_;

	return $f =~ /\.jpe?g$/i;			## no critic
	# TODO: should we use something more complicated here? maybe mime type?
}   

1;

__END__