source: extensions/pLoader/trunk/src/Uploader/Image.pm @ 6426

Last change on this file since 6426 was 6426, checked in by ronosman, 14 years ago

Bug 1710 fixed : pLoader lack of concurrency support causes data inconsistency.

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
1# +-----------------------------------------------------------------------+
2# | pLoader - a Perl photo uploader for Piwigo                            |
3# +-----------------------------------------------------------------------+
4# | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
5# +-----------------------------------------------------------------------+
6# | This program is free software; you can redistribute it and/or modify  |
7# | it under the terms of the GNU General Public License as published by  |
8# | the Free Software Foundation                                          |
9# |                                                                       |
10# | This program is distributed in the hope that it will be useful, but   |
11# | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13# | General Public License for more details.                              |
14# |                                                                       |
15# | You should have received a copy of the GNU General Public License     |
16# | along with this program; if not, write to the Free Software           |
17# | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18# | USA.                                                                  |
19# +-----------------------------------------------------------------------+
20package Uploader::Image;
21use strict;
22use base qw/Uploader::Object/;
23use File::Spec;
24use Image::ExifTool qw(:Public);
25use Data::Dumper;
26
27# we need a ref to data preferences to use with threads
28my @properties = qw/
29    file
30    wx_thumb_file
31    site_high_file
32    site_name
33    site_resized_file
34    site_thumb_file
35    site_author
36    site_comment
37    site_original_filename
38    exif_metadata
39    add_rank
40    site_categories
41    site_tags
42    image_id
43    width
44    height
45    privacy_level
46    caption
47    global_rank
48/;
49
50my $init_caption_from_pattern_cbk;
51
52__PACKAGE__->mk_accessors(@properties);
53
54sub Init {
55    my ( $self ) = @_;
56
57
58    my $exif = $self->read_exif_metadata(
59        $self->file
60    );
61
62    $self->exif_metadata(
63        $self->select_exif_data($exif)
64    );
65
66       
67
68    $self->site_original_filename(
69        $self->original_filename
70    );
71
72}
73
74
75sub read_exif_metadata {
76    my ( $self, $file ) = @_;
77   
78    # read exif metadata
79    my $info;
80    eval {
81        $info = ImageInfo( $file );
82    };
83    $info = {} if($@);
84   
85    $info;
86}
87
88
89sub exif_tag {
90    my ( $self, $tag ) = @_;
91
92    my $exif = $self->exif_metadata ;
93   
94    $exif->{$tag};
95}
96
97
98sub create_date {
99    my ( $self, $date ) = @_;
100   
101    my $exif = $self->exif_metadata ;
102   
103    $self->{-create_date} ||= $exif->{CreateDate};
104
105    $self->{-create_date} = $date if defined $date;
106
107    $self->{-create_date};
108}
109
110
111sub select_exif_data {
112    my ( $self, $exif ) = @_;
113
114    return {
115        map {
116            $_ => $exif->{$_},
117        }
118        qw/
119            CreateDate
120            ImageWidth
121            ImageHeight
122            Orientation
123            DateTimeOriginal
124            ISO
125            ExposureTime
126            ApertureValue
127            FocalLength
128            Lens
129            Exposure
130            Make
131            Model
132        /
133    };   
134}
135
136
137sub original_filename {
138    my ( $self ) = @_;
139
140    my ( $vol, $dir, $filename ) = File::Spec->splitpath(
141        $self->file
142    );
143
144    $filename;
145}
146
147sub get_data {
148    my ( $self, $preferences, $destination_category, $add_rank ) = @_;
149
150    my $data = {
151        map { $_ => $self->$_ } @properties
152    };
153    $data->{preferences} = $preferences;
154    $data->{categories}  = $destination_category;
155    $data->{site_img_date_creation} = $self->create_date;
156    $data->{add_rank} = $add_rank;
157
158    return $data;
159}
160
1611;
Note: See TracBrowser for help on using the repository browser.