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 | # +-----------------------------------------------------------------------+ |
---|
20 | package Uploader::Image; |
---|
21 | use strict; |
---|
22 | use base qw/Uploader::Object/; |
---|
23 | use File::Spec; |
---|
24 | use Image::ExifTool qw(:Public); |
---|
25 | use Data::Dumper; |
---|
26 | |
---|
27 | # we need a ref to data preferences to use with threads |
---|
28 | my @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_tags |
---|
41 | image_id |
---|
42 | width |
---|
43 | height |
---|
44 | privacy_level |
---|
45 | caption |
---|
46 | global_rank |
---|
47 | /; |
---|
48 | |
---|
49 | my $init_caption_from_pattern_cbk; |
---|
50 | |
---|
51 | __PACKAGE__->mk_accessors(@properties); |
---|
52 | |
---|
53 | sub Init { |
---|
54 | my ( $self ) = @_; |
---|
55 | |
---|
56 | |
---|
57 | my $exif = $self->read_exif_metadata( |
---|
58 | $self->file |
---|
59 | ); |
---|
60 | |
---|
61 | $self->exif_metadata( |
---|
62 | $self->select_exif_data($exif) |
---|
63 | ); |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | $self->site_original_filename( |
---|
68 | $self->original_filename |
---|
69 | ); |
---|
70 | |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | sub read_exif_metadata { |
---|
75 | my ( $self, $file ) = @_; |
---|
76 | |
---|
77 | # read exif metadata |
---|
78 | my $info; |
---|
79 | eval { |
---|
80 | $info = ImageInfo( $file ); |
---|
81 | }; |
---|
82 | $info = {} if($@); |
---|
83 | |
---|
84 | $info; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | sub exif_tag { |
---|
89 | my ( $self, $tag ) = @_; |
---|
90 | |
---|
91 | my $exif = $self->exif_metadata ; |
---|
92 | |
---|
93 | $exif->{$tag}; |
---|
94 | } |
---|
95 | |
---|
96 | |
---|
97 | sub create_date { |
---|
98 | my ( $self, $date ) = @_; |
---|
99 | |
---|
100 | my $exif = $self->exif_metadata ; |
---|
101 | |
---|
102 | $self->{-create_date} ||= $exif->{CreateDate}; |
---|
103 | |
---|
104 | $self->{-create_date} = $date if defined $date; |
---|
105 | |
---|
106 | $self->{-create_date}; |
---|
107 | } |
---|
108 | |
---|
109 | |
---|
110 | sub select_exif_data { |
---|
111 | my ( $self, $exif ) = @_; |
---|
112 | |
---|
113 | return { |
---|
114 | map { |
---|
115 | $_ => $exif->{$_}, |
---|
116 | } |
---|
117 | qw/ |
---|
118 | CreateDate |
---|
119 | ImageWidth |
---|
120 | ImageHeight |
---|
121 | Orientation |
---|
122 | DateTimeOriginal |
---|
123 | ISO |
---|
124 | ExposureTime |
---|
125 | ApertureValue |
---|
126 | FocalLength |
---|
127 | Lens |
---|
128 | Exposure |
---|
129 | Make |
---|
130 | Model |
---|
131 | / |
---|
132 | }; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | sub original_filename { |
---|
137 | my ( $self ) = @_; |
---|
138 | |
---|
139 | my ( $vol, $dir, $filename ) = File::Spec->splitpath( |
---|
140 | $self->file |
---|
141 | ); |
---|
142 | |
---|
143 | $filename; |
---|
144 | } |
---|
145 | |
---|
146 | sub get_data { |
---|
147 | my ( $self, $preferences, $destination_category, $add_rank ) = @_; |
---|
148 | |
---|
149 | my $data = { |
---|
150 | map { $_ => $self->$_ } @properties |
---|
151 | }; |
---|
152 | $data->{preferences} = $preferences; |
---|
153 | $data->{categories} = $destination_category; |
---|
154 | $data->{site_img_date_creation} = $self->create_date; |
---|
155 | $data->{add_rank} = $add_rank; |
---|
156 | |
---|
157 | return $data; |
---|
158 | } |
---|
159 | |
---|
160 | 1; |
---|