| 1 | package App::Followme::JpegData; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use 5.008005; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use integer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use lib '../..'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | use base qw(App::Followme::FileData); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | use Image::Size; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use File::Spec::Functions qw(catfile); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use App::Followme::FIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 3 | our $VERSION = "2.03"; | |||||||||
| 16 | |||||||||||
| 17 | #---------------------------------------------------------------------- | ||||||||||
| 18 | # Read the default parameter values | ||||||||||
| 19 | |||||||||||
| 20 | 16 | ▶ | sub parameters { | ||||||||
|
Subroutine
parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 21 | 16 | my ($self) = @_; | |||||||||
| 22 | |||||||||||
| 23 | return ( | ||||||||||
| 24 | 16 | extension => 'jpg', | |||||||||
| 25 | target_prefix => 'img', | ||||||||||
| 26 | thumb_suffix => '-thumb', | ||||||||||
| 27 | ); | ||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | #---------------------------------------------------------------------- | ||||||||||
| 31 | # Look in the file for the data | ||||||||||
| 32 | |||||||||||
| 33 | 19 | ▶ | sub fetch_from_file { | ||||||||
|
Subroutine
fetch_from_file: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 34 | 19 | my ($self, $filename) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 19 | ▶ | return () unless -e $filename; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 12 | ▶ | return $self->SUPER::fetch_from_file($filename) if -T $filename; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 5 | my %dimensions; | |||||||||
| 40 | 5 | ($dimensions{width}, $dimensions{height}) = imgsize($filename); | |||||||||
| 41 | |||||||||||
| 42 | 5 | return %dimensions; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | #---------------------------------------------------------------------- | ||||||||||
| 46 | # Get the name of the thumb photo file | ||||||||||
| 47 | |||||||||||
| 48 | 20 | ▶ | sub get_thumb_file { | ||||||||
|
Subroutine
get_thumb_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 49 | 20 | my ($self, $filename) = @_; | |||||||||
| 50 | |||||||||||
| 51 | 20 | my ($dir, $file) = fio_split_filename($filename); | |||||||||
| 52 | 20 | my ($root, $ext) = split(/\./, $file); | |||||||||
| 53 | 20 | $file = join('', $root, $self->{thumb_suffix}, '.', $ext); | |||||||||
| 54 | 20 | my $photoname = catfile($dir, $file); | |||||||||
| 55 | |||||||||||
| 56 | 20 | return [$photoname]; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | #---------------------------------------------------------------------- | ||||||||||
| 60 | # Get a url from a filename | ||||||||||
| 61 | |||||||||||
| 62 | 20 | ▶ | sub get_url { | ||||||||
|
Subroutine
get_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | 20 | my ($self, $filename) = @_; | |||||||||
| 64 | |||||||||||
| 65 | return $self->filename_to_url($self->{top_directory}, | ||||||||||
| 66 | 20 | $filename); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | #---------------------------------------------------------------------- | ||||||||||
| 70 | # Set up exclude | ||||||||||
| 71 | |||||||||||
| 72 | 4 | ▶ | sub setup { | ||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 73 | 4 | my ($self) = @_; | |||||||||
| 74 | |||||||||||
| 75 | 4 | my $dir; | |||||||||
| 76 | 4 | my $thumb_files = $self->get_thumb_file("*.$self->{extension}"); | |||||||||
| 77 | 4 | ($dir, $self->{exclude}) = fio_split_filename($thumb_files->[0]); | |||||||||
| 78 | |||||||||||
| 79 | 4 | return; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 3 | 1; | |||||||||
| 83 | |||||||||||
| 84 | =pod | ||||||||||
| 85 | |||||||||||
| 86 | =encoding utf-8 | ||||||||||
| 87 | |||||||||||
| 88 | =head1 NAME | ||||||||||
| 89 | |||||||||||
| 90 | App::Followme::JpegData - Read datafrom a jpeg file | ||||||||||
| 91 | |||||||||||
| 92 | =head1 SYNOPSIS | ||||||||||
| 93 | |||||||||||
| 94 | use App::Followme::JpegData; | ||||||||||
| 95 | my $data = App::Followme::JpegData->new(); | ||||||||||
| 96 | my $html = App::Followme::Template->new('example.htm', $data); | ||||||||||
| 97 | |||||||||||
| 98 | =head1 DESCRIPTION | ||||||||||
| 99 | |||||||||||
| 100 | This module extratcs metadata from a jpeg image and uses that metadata to | ||||||||||
| 101 | build variables used in a template. | ||||||||||
| 102 | |||||||||||
| 103 | =head1 METHODS | ||||||||||
| 104 | |||||||||||
| 105 | All data classes are first instantiated by calling new and the object | ||||||||||
| 106 | created is passed to a template object. It calls the build method with an | ||||||||||
| 107 | argument name to retrieve that data item, though for the sake of | ||||||||||
| 108 | efficiency, all the data are read from the file at once. | ||||||||||
| 109 | |||||||||||
| 110 | =head1 VARIABLES | ||||||||||
| 111 | |||||||||||
| 112 | =over 4 | ||||||||||
| 113 | |||||||||||
| 114 | =item @thumb_file | ||||||||||
| 115 | |||||||||||
| 116 | The name of the thumb file for a photo. Even though this is a single file, it | ||||||||||
| 117 | is returned as a hash and thus must be used in a for statement. | ||||||||||
| 118 | |||||||||||
| 119 | =item $height | ||||||||||
| 120 | |||||||||||
| 121 | The height of the photo | ||||||||||
| 122 | |||||||||||
| 123 | =item $width | ||||||||||
| 124 | |||||||||||
| 125 | The width of the photo | ||||||||||
| 126 | |||||||||||
| 127 | =back | ||||||||||
| 128 | |||||||||||
| 129 | =head1 CONFIGURATION | ||||||||||
| 130 | |||||||||||
| 131 | The following fields in the configuration file are used in this class and every | ||||||||||
| 132 | class based on it: | ||||||||||
| 133 | |||||||||||
| 134 | =over 4 | ||||||||||
| 135 | |||||||||||
| 136 | =item extension | ||||||||||
| 137 | |||||||||||
| 138 | The extension used by jpeg files. | ||||||||||
| 139 | |||||||||||
| 140 | =item target_prefix | ||||||||||
| 141 | |||||||||||
| 142 | The prefix used to build the target names. The default value is 'img'. | ||||||||||
| 143 | |||||||||||
| 144 | =item thumb_suffix | ||||||||||
| 145 | |||||||||||
| 146 | The suffix added to the root of the photo filename to build the thumb photo | ||||||||||
| 147 | filename. The default value is '-thumb'. | ||||||||||
| 148 | |||||||||||
| 149 | =back | ||||||||||
| 150 | |||||||||||
| 151 | =head1 LICENSE | ||||||||||
| 152 | |||||||||||
| 153 | Copyright (C) Bernie Simon. | ||||||||||
| 154 | |||||||||||
| 155 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 156 | it under the same terms as Perl itself. | ||||||||||
| 157 | |||||||||||
| 158 | =head1 AUTHOR | ||||||||||
| 159 | |||||||||||
| 160 | Bernie Simon E<lt>bernie.simon@gmail.comE<gt> | ||||||||||
| 161 | |||||||||||
| 162 | =cut | ||||||||||