App-Followme

 view release on metacpan or  search on metacpan

lib/App/Followme/JpegData.pm  view on Meta::CPAN

package App::Followme::JpegData;

use 5.008005;
use strict;
use warnings;
use integer;
use lib '../..';

use base qw(App::Followme::FileData);

use Image::Size;
use File::Spec::Functions qw(catfile);
use App::Followme::FIO;

our $VERSION = "2.03";

#----------------------------------------------------------------------
# Read the default parameter values

sub parameters {
    my ($self) = @_;

    return (
            extension => 'jpg',
            target_prefix => 'img',
            thumb_suffix => '-thumb',
           );
}

#----------------------------------------------------------------------
# Look in the file for the data

sub fetch_from_file {
    my ($self, $filename) = @_;

    return () unless -e $filename;
    return $self->SUPER::fetch_from_file($filename) if -T $filename;

    my %dimensions;
    ($dimensions{width}, $dimensions{height}) = imgsize($filename);

    return %dimensions;
}

#----------------------------------------------------------------------
# Get the name of the thumb photo file

sub get_thumb_file {
    my ($self, $filename) = @_;

    my ($dir, $file) = fio_split_filename($filename);
    my ($root, $ext) = split(/\./, $file);
    $file = join('', $root, $self->{thumb_suffix}, '.', $ext);
    my $photoname = catfile($dir, $file);

    return [$photoname];
}

#----------------------------------------------------------------------
# Get a url from a filename

sub get_url {
    my ($self, $filename) = @_;

    return $self->filename_to_url($self->{top_directory},
                                  $filename);
}

#----------------------------------------------------------------------
# Set up exclude

sub setup {
    my ($self) = @_;

    my $dir;
    my $thumb_files = $self->get_thumb_file("*.$self->{extension}");
    ($dir, $self->{exclude}) = fio_split_filename($thumb_files->[0]);

    return;
}

1;

=pod

=encoding utf-8

=head1 NAME

App::Followme::JpegData - Read datafrom a jpeg file

=head1 SYNOPSIS

    use App::Followme::JpegData;
    my $data = App::Followme::JpegData->new();
    my $html = App::Followme::Template->new('example.htm', $data);



( run in 1.337 second using v1.01-cache-2.11-cpan-ceb78f64989 )