[2597] | 1 | # +-----------------------------------------------------------------------+ |
---|
| 2 | # | pLoader - a Perl photo uploader for Piwigo | |
---|
| 3 | # +-----------------------------------------------------------------------+ |
---|
| 4 | # | Copyright(C) 2008 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::ImageList; |
---|
| 21 | use strict; |
---|
[2696] | 22 | use Carp; |
---|
[2597] | 23 | use base qw/Uploader::Object/; |
---|
| 24 | use Image::ExifTool qw(:Public); |
---|
| 25 | use Image::Magick; |
---|
| 26 | use File::Spec; |
---|
| 27 | use Uploader::Image; |
---|
| 28 | use Data::Dumper; |
---|
| 29 | use Storable; |
---|
[3226] | 30 | use Digest::MD5::File qw/file_md5_hex md5_hex/; |
---|
| 31 | use Encode qw/encode decode is_utf8/; |
---|
[3267] | 32 | use Wx::Locale qw/:default/; |
---|
[3226] | 33 | |
---|
[2597] | 34 | # this class implements a collection of image files with associated data |
---|
[2696] | 35 | $|=1; |
---|
[2597] | 36 | __PACKAGE__->mk_accessors( |
---|
| 37 | qw/ |
---|
| 38 | thumb_size |
---|
| 39 | preview_ratio |
---|
| 40 | categories |
---|
| 41 | type |
---|
| 42 | filter |
---|
| 43 | blur |
---|
| 44 | quality |
---|
| 45 | prefix |
---|
| 46 | author |
---|
| 47 | count |
---|
| 48 | resize_w |
---|
| 49 | resize_h |
---|
| 50 | new_files |
---|
| 51 | storable_file |
---|
| 52 | wx_thumb_size |
---|
| 53 | current_image |
---|
| 54 | images |
---|
| 55 | image_selection |
---|
| 56 | exif_metadata |
---|
| 57 | wx_thumb_imglist |
---|
| 58 | wx_thumb_dir |
---|
| 59 | preview_dir |
---|
| 60 | site_resized_dir |
---|
| 61 | site_thumb_dir |
---|
| 62 | userdata_dir |
---|
| 63 | progress_msg |
---|
[2661] | 64 | last_error_msg |
---|
[3267] | 65 | default_photo_name |
---|
| 66 | default_photo_name_method |
---|
[2597] | 67 | default_name_prefix |
---|
| 68 | SetNewFilesViewerRefreshCallback |
---|
| 69 | SetNewFilesProgressCallback |
---|
[2696] | 70 | SetNewFilesDisplayEndInfoCallback |
---|
[2597] | 71 | UploadImagesViewerCallback |
---|
[2728] | 72 | progress_thumbnail_refresh |
---|
| 73 | progress_msg_refresh |
---|
| 74 | progressbar_refresh |
---|
| 75 | progress_endinfo_refresh |
---|
[3226] | 76 | RescaleCallback |
---|
[2661] | 77 | ResizeCallback |
---|
[2597] | 78 | upload_rejects |
---|
| 79 | pwg |
---|
[2696] | 80 | upload_high |
---|
[3286] | 81 | remove_uploaded_from_selection |
---|
[3177] | 82 | wx_quality |
---|
| 83 | th_quality |
---|
| 84 | auto_rotate |
---|
| 85 | interlace |
---|
| 86 | create_resized |
---|
| 87 | use_exif_preview |
---|
[3226] | 88 | image_sums |
---|
| 89 | sums |
---|
| 90 | version |
---|
| 91 | imagelist_version |
---|
[2597] | 92 | / |
---|
| 93 | ); |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | sub Init { |
---|
[3267] | 97 | my ( $self ) = @_; |
---|
| 98 | |
---|
| 99 | |
---|
[2597] | 100 | } |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
[2661] | 104 | # save exif preview image if available |
---|
| 105 | # otherwise create a preview image |
---|
| 106 | sub _write_preview_image { |
---|
| 107 | my ( $self, $imagedata ) = @_; |
---|
[2597] | 108 | |
---|
| 109 | |
---|
| 110 | # If PreviewImage is available, we use it |
---|
[2661] | 111 | if(defined $imagedata ) { |
---|
[3226] | 112 | print "_write_preview_image, use exif PreviewImage\n"; |
---|
[2597] | 113 | eval { |
---|
| 114 | open PREVIEW_FILE, ">", $self->current_image->preview_file ; |
---|
| 115 | binmode PREVIEW_FILE; |
---|
[2661] | 116 | print PREVIEW_FILE $$imagedata; |
---|
[2597] | 117 | close PREVIEW_FILE; |
---|
| 118 | }; |
---|
[2661] | 119 | $self->last_error_msg($@) if $@; |
---|
[2597] | 120 | } |
---|
| 121 | |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
[2696] | 125 | sub _set_exif_tag { |
---|
| 126 | my ( $self, $file, $tag, $newValue ) = @_; |
---|
| 127 | |
---|
| 128 | my $options = {}; |
---|
| 129 | # Create a new Image::ExifTool object |
---|
| 130 | my $exifTool = new Image::ExifTool; |
---|
| 131 | |
---|
| 132 | # Extract meta information from an image |
---|
| 133 | $exifTool->ExtractInfo($file, $options); |
---|
| 134 | |
---|
| 135 | # Set a new value for a tag |
---|
| 136 | $exifTool->SetNewValue($tag, $newValue); |
---|
| 137 | |
---|
| 138 | # Write new meta information to a file |
---|
| 139 | $exifTool->WriteInfo($file); |
---|
| 140 | |
---|
| 141 | } |
---|
| 142 | |
---|
[3226] | 143 | sub _set_current_image_filepaths__ { |
---|
[2597] | 144 | my ( $self ) = @_; |
---|
| 145 | |
---|
| 146 | my ( $vol, $dir, $file ) = File::Spec->splitpath( |
---|
| 147 | $self->current_image->file |
---|
| 148 | ); |
---|
| 149 | |
---|
| 150 | my ( $filename, $ext ) = split /\./, $file ; |
---|
[3226] | 151 | |
---|
[2597] | 152 | |
---|
| 153 | $self->current_image->wx_thumb_file( |
---|
| 154 | File::Spec->catfile( |
---|
| 155 | $self->wx_thumb_dir, |
---|
| 156 | sprintf( |
---|
| 157 | "%s.%s", |
---|
| 158 | $filename, |
---|
| 159 | $self->type, |
---|
| 160 | ) |
---|
| 161 | ) |
---|
| 162 | ); |
---|
| 163 | |
---|
| 164 | $self->current_image->preview_file( |
---|
| 165 | File::Spec->catfile( |
---|
| 166 | $self->preview_dir, |
---|
| 167 | sprintf( |
---|
| 168 | "%s.%s", |
---|
| 169 | $filename, |
---|
| 170 | $self->type, |
---|
| 171 | ) |
---|
| 172 | ) |
---|
| 173 | ); |
---|
[3226] | 174 | $self->current_image->preview_file( |
---|
| 175 | encode('iso-8859-1', $self->current_image->preview_file) |
---|
| 176 | ); |
---|
[2597] | 177 | |
---|
| 178 | $self->current_image->site_thumb_file( |
---|
| 179 | File::Spec->catfile( |
---|
| 180 | $self->site_thumb_dir, |
---|
| 181 | sprintf( |
---|
| 182 | "%s.%s", |
---|
| 183 | $filename, |
---|
| 184 | $self->type, |
---|
| 185 | ) |
---|
| 186 | ) |
---|
| 187 | ); |
---|
| 188 | |
---|
| 189 | } |
---|
| 190 | |
---|
[3226] | 191 | sub _set_current_image_filepaths { |
---|
| 192 | my ( $self ) = @_; |
---|
| 193 | |
---|
| 194 | my $filename = sprintf( |
---|
| 195 | "%s.%s", |
---|
| 196 | $self->current_image->file_sum, |
---|
| 197 | $self->type, |
---|
| 198 | ); |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | $self->current_image->wx_thumb_file( |
---|
| 202 | File::Spec->catfile( |
---|
| 203 | $self->wx_thumb_dir, |
---|
| 204 | $filename |
---|
| 205 | ) |
---|
| 206 | ); |
---|
| 207 | |
---|
| 208 | $self->current_image->preview_file( |
---|
| 209 | File::Spec->catfile( |
---|
| 210 | $self->preview_dir, |
---|
| 211 | $filename |
---|
| 212 | ) |
---|
| 213 | ); |
---|
| 214 | $self->current_image->preview_file( |
---|
| 215 | encode('iso-8859-1', $self->current_image->preview_file) |
---|
| 216 | ); |
---|
| 217 | |
---|
| 218 | $self->current_image->site_thumb_file( |
---|
| 219 | File::Spec->catfile( |
---|
| 220 | $self->site_thumb_dir, |
---|
| 221 | $filename |
---|
| 222 | ) |
---|
| 223 | ); |
---|
| 224 | |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | |
---|
[2597] | 228 | sub SetCurrentImage { |
---|
| 229 | my ( $self, $indx ) = @_; |
---|
| 230 | |
---|
| 231 | $self->current_image( |
---|
[3226] | 232 | $self->GetImage($indx) |
---|
[2597] | 233 | ); |
---|
| 234 | } |
---|
| 235 | |
---|
[2661] | 236 | |
---|
[2597] | 237 | sub SetNewFiles { |
---|
| 238 | my ( $self, $files ) = @_; |
---|
[2661] | 239 | |
---|
[2597] | 240 | $self->new_files( $files ); |
---|
| 241 | |
---|
| 242 | # if some files have been previously selected |
---|
[3226] | 243 | my $i = scalar @{$self->sums}; |
---|
[2696] | 244 | my $count = 0; |
---|
| 245 | $self->count($count); |
---|
[2730] | 246 | my $errors = 0; |
---|
[3226] | 247 | |
---|
[2597] | 248 | map { |
---|
[3226] | 249 | my $info = $self->_read_exif_metatdata($_); |
---|
| 250 | my $is_new_image = $self->_add_image($_, $info, $i); |
---|
[2661] | 251 | $self->SetCurrentImage($i); |
---|
| 252 | $self->_set_current_image_filepaths(); |
---|
| 253 | |
---|
[3226] | 254 | if($is_new_image){ |
---|
| 255 | my $use_wx_resize = $self->_create_gui_preview($info); |
---|
| 256 | $self->_create_gui_thumbnail($use_wx_resize); |
---|
| 257 | |
---|
| 258 | # ok |
---|
| 259 | if(!$@){ |
---|
| 260 | $self->progress_msg("Thumbnail and preview created for %s"); |
---|
[3177] | 261 | } |
---|
| 262 | else { |
---|
[3226] | 263 | $self->progress_msg("An error has occured when processing %s\n$@"); |
---|
| 264 | # remove from list |
---|
| 265 | splice @{$self->sums}, $i, 1; |
---|
| 266 | $errors++; |
---|
[3177] | 267 | } |
---|
[3226] | 268 | |
---|
| 269 | $self->SetNewFilesProgressCallback->(); |
---|
[3177] | 270 | } |
---|
[3226] | 271 | $i++; |
---|
| 272 | $count++; |
---|
| 273 | $self->count($count); |
---|
[2661] | 274 | $self->SetNewFilesViewerRefreshCallback->(); |
---|
[2597] | 275 | } |
---|
| 276 | @{$files}; |
---|
[2730] | 277 | $self->SetNewFilesDisplayEndInfoCallback->( |
---|
| 278 | sprintf( |
---|
| 279 | "%s images added to the selection\n\n%s errors", |
---|
| 280 | $self->count, |
---|
| 281 | $errors |
---|
| 282 | |
---|
| 283 | ) |
---|
| 284 | ); |
---|
[2597] | 285 | |
---|
| 286 | $self->Store; |
---|
| 287 | |
---|
| 288 | } |
---|
| 289 | |
---|
[3226] | 290 | sub _read_exif_metatdata { |
---|
| 291 | my ( $self, $file ) = @_; |
---|
| 292 | |
---|
| 293 | # read exif metadata |
---|
| 294 | my $info; |
---|
| 295 | eval { |
---|
| 296 | $info = ImageInfo( $file ); |
---|
| 297 | }; |
---|
| 298 | $info = {} if($@); |
---|
| 299 | |
---|
| 300 | $info; |
---|
| 301 | } |
---|
| 302 | |
---|
[2597] | 303 | # key is file path |
---|
| 304 | sub _add_image { |
---|
| 305 | my ( $self, $file, $info, $i ) = @_; |
---|
| 306 | |
---|
[3226] | 307 | my $is_new_image; |
---|
| 308 | |
---|
| 309 | # for legacy imagelist that do not have image_sums property |
---|
| 310 | $self->image_sums( |
---|
| 311 | {} |
---|
| 312 | ) if !$self->image_sums; |
---|
| 313 | |
---|
| 314 | my $sum = file_md5_hex($file); |
---|
| 315 | |
---|
| 316 | my $image; |
---|
| 317 | if ( !exists $self->image_sums->{$sum} ){ |
---|
[3267] | 318 | print "_add_image ", $file, "\n"; |
---|
[3226] | 319 | # append to image list |
---|
| 320 | $image = Uploader::Image->new( |
---|
[2597] | 321 | { |
---|
[3267] | 322 | file => $file, |
---|
[3226] | 323 | file_sum => $sum, |
---|
[3267] | 324 | site_name => $self->_default_photo_name($file, $info, $i), |
---|
[3226] | 325 | site_author => $self->author, |
---|
| 326 | exif_metadata => $self->_select_exif_data($info), |
---|
| 327 | add_rank => $i, |
---|
| 328 | site_categories => [], |
---|
| 329 | site_tags => [], |
---|
| 330 | site_high_file => $_, |
---|
| 331 | } |
---|
| 332 | ); |
---|
| 333 | |
---|
| 334 | $self->image_sums->{$sum} = $image ; |
---|
| 335 | $is_new_image = 1; |
---|
| 336 | } else { |
---|
| 337 | $image = $self->image_sums->{$sum}; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | $self->sums->[$i] = $sum ; |
---|
| 342 | |
---|
| 343 | $is_new_image; |
---|
| 344 | } |
---|
| 345 | |
---|
[3267] | 346 | |
---|
| 347 | sub _default_photo_name { |
---|
| 348 | my ( $self, $file, $info, $i ) = @_; |
---|
| 349 | |
---|
[3360] | 350 | # $file = encode('iso-8859-1', $file); |
---|
[3286] | 351 | |
---|
[3267] | 352 | my $name; |
---|
| 353 | my $create_date = $info->{CreateDate}; |
---|
| 354 | my $ext; |
---|
| 355 | my ( $vol, $path, $filename ) = File::Spec->splitpath($file); |
---|
| 356 | ( $filename, $ext ) = split /\.\w+$/, $filename; |
---|
| 357 | |
---|
| 358 | my ( $yyyy, $mm, $dd, $hh, $mi, $ss ) = split /[:\s]/, $create_date ; |
---|
| 359 | |
---|
| 360 | my $chrono = join('', $yyyy, $mm, $dd); |
---|
| 361 | if(gettext('Prefix') eq $self->default_photo_name){ |
---|
| 362 | $name = $self->default_name_prefix |
---|
| 363 | } |
---|
| 364 | elsif(gettext('File name') eq $self->default_photo_name){ |
---|
| 365 | $name = $filename |
---|
| 366 | } |
---|
| 367 | elsif(gettext('File path and name') eq $self->default_photo_name){ |
---|
| 368 | $name = sprintf( |
---|
| 369 | "%s", |
---|
| 370 | File::Spec->catfile($path, $filename), |
---|
| 371 | ) |
---|
| 372 | } |
---|
| 373 | elsif(gettext('Prefix + rank number') eq $self->default_photo_name){ |
---|
| 374 | $name = sprintf( |
---|
| 375 | "%s%s", |
---|
| 376 | $self->default_name_prefix, |
---|
| 377 | 1+$i, |
---|
| 378 | ) |
---|
| 379 | } |
---|
| 380 | elsif(gettext('Rank number + prefix') eq $self->default_photo_name){ |
---|
| 381 | $name = sprintf( |
---|
| 382 | "%s%s", |
---|
| 383 | 1+$i, |
---|
| 384 | $self->default_name_prefix, |
---|
| 385 | ) |
---|
| 386 | } |
---|
| 387 | elsif(gettext('Prefix + create date chrono') eq $self->default_photo_name){ |
---|
| 388 | $name = sprintf( |
---|
| 389 | "%s%s", |
---|
| 390 | $self->default_name_prefix, |
---|
| 391 | $chrono, |
---|
| 392 | ) |
---|
| 393 | } |
---|
| 394 | elsif(gettext('Create date chrono + prefix') eq $self->default_photo_name){ |
---|
| 395 | $name = sprintf( |
---|
| 396 | "%s%s", |
---|
| 397 | $chrono, |
---|
| 398 | $self->default_name_prefix, |
---|
| 399 | ) |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | $name; |
---|
| 403 | } |
---|
| 404 | |
---|
[3226] | 405 | sub _create_gui_preview { |
---|
| 406 | my ( $self, $info ) = @_; |
---|
| 407 | |
---|
| 408 | my $create_gui_preview; |
---|
| 409 | my $use_wx_resize; |
---|
| 410 | if($self->use_exif_preview){ |
---|
| 411 | # an exif preview is available. we try to use it |
---|
| 412 | if(defined $info->{PreviewImage} ){ |
---|
| 413 | printf("use preview\n"); |
---|
| 414 | $self->_write_preview_image( $info->{PreviewImage} ); |
---|
| 415 | my $image = new Image::Magick; |
---|
| 416 | eval { |
---|
| 417 | $create_gui_preview = $image->ReadImage( |
---|
| 418 | $self->current_image->preview_file |
---|
| 419 | ); |
---|
| 420 | }; |
---|
| 421 | unlink $self->current_image->preview_file if $create_gui_preview; |
---|
[2597] | 422 | } |
---|
[3226] | 423 | else { |
---|
| 424 | $create_gui_preview = 1; |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | else { |
---|
| 428 | $create_gui_preview = 1; |
---|
| 429 | } |
---|
| 430 | print "create gui preview", $create_gui_preview, "\n"; |
---|
| 431 | # have to create a preview file |
---|
| 432 | if($create_gui_preview) { |
---|
| 433 | eval { |
---|
| 434 | if(!$self->CreateGUIPreview()){ |
---|
| 435 | # use method provided by the caller |
---|
| 436 | # source, target, type, ratio |
---|
| 437 | print "CreateGUIPreview failed, use callback\n"; |
---|
| 438 | $self->RescaleCallback->( |
---|
| 439 | $self->current_image->file, |
---|
| 440 | $self->current_image->preview_file, |
---|
| 441 | $self->type, |
---|
| 442 | $self->preview_ratio, |
---|
| 443 | undef, |
---|
| 444 | undef, |
---|
| 445 | $self->quality, |
---|
| 446 | ); |
---|
| 447 | $use_wx_resize = 1; |
---|
| 448 | } |
---|
| 449 | };# create a preview file |
---|
| 450 | } |
---|
[2597] | 451 | |
---|
[3226] | 452 | $self->RotateImage( |
---|
| 453 | $self->current_image->preview_file, |
---|
| 454 | ) if $self->auto_rotate; |
---|
[2597] | 455 | |
---|
[3226] | 456 | $self->_set_exif_tag( |
---|
| 457 | $self->current_image->preview_file, |
---|
| 458 | 'Orientation', |
---|
| 459 | 'Horizontal (normal)', |
---|
| 460 | ) if $self->auto_rotate; |
---|
| 461 | |
---|
| 462 | $use_wx_resize; |
---|
[2597] | 463 | } |
---|
| 464 | |
---|
[3226] | 465 | sub _create_gui_thumbnail { |
---|
| 466 | my ( $self, $use_wx_resize ) = @_; |
---|
[2597] | 467 | |
---|
[3226] | 468 | # Now, we should have a valid preview image. |
---|
| 469 | # try to thumbnail it |
---|
| 470 | eval { |
---|
| 471 | printf("create gui thumbnail\n"); |
---|
| 472 | # use the preview image to create a gui display thumbnail |
---|
| 473 | if($use_wx_resize) |
---|
| 474 | { |
---|
| 475 | print "CreateGUIThumbnail failed, use callback\n"; |
---|
| 476 | $self->ResizeCallback->( |
---|
| 477 | $self->current_image->preview_file, |
---|
| 478 | $self->current_image->wx_thumb_file, |
---|
| 479 | $self->type, |
---|
| 480 | $self->wx_thumb_size, |
---|
| 481 | $self->wx_thumb_size, |
---|
| 482 | $self->wx_quality, |
---|
| 483 | ); |
---|
| 484 | |
---|
| 485 | } else { |
---|
| 486 | $self->CreateGUIThumbnail(); |
---|
| 487 | } |
---|
| 488 | }; |
---|
| 489 | } |
---|
| 490 | |
---|
[2597] | 491 | sub RemoveImageSelection { |
---|
| 492 | my ( $self ) = @_; |
---|
| 493 | |
---|
[3226] | 494 | return if (! scalar @{$self->sums} ); |
---|
[2618] | 495 | return if (! defined $self->image_selection ); |
---|
[2597] | 496 | |
---|
| 497 | # higher first, to keep same indexes during remove |
---|
| 498 | my @images = reverse @{$self->image_selection}; |
---|
| 499 | map { |
---|
[3366] | 500 | #my $image = $self->GetImage($_)->file; |
---|
| 501 | $self->DeleteImage($_); |
---|
[3226] | 502 | splice @{$self->sums}, $_, 1 ; |
---|
[2597] | 503 | $self->wx_thumb_imglist->Remove($_); |
---|
| 504 | shift @images; |
---|
| 505 | } |
---|
| 506 | @images; |
---|
[2618] | 507 | |
---|
| 508 | # clear image selection |
---|
| 509 | $self->image_selection([]); |
---|
[2597] | 510 | } |
---|
| 511 | |
---|
| 512 | # used for display in GUI. has to fit a square box ( wxImageList ) |
---|
| 513 | sub CreateGUIThumbnail { |
---|
| 514 | my ( $self ) = @_; |
---|
| 515 | |
---|
| 516 | return 1 if( -e $self->current_image->wx_thumb_file ); |
---|
[2661] | 517 | my $rval = 0; |
---|
[3226] | 518 | print "CreateGUIThumbnail ", $self->current_image->wx_thumb_file, "\n"; |
---|
[2597] | 519 | my $image = new Image::Magick; |
---|
| 520 | |
---|
| 521 | my $size = $self->wx_thumb_size; |
---|
| 522 | |
---|
| 523 | my $status = $image->Set(size=>sprintf("%sx%s", 3*$size, 3*$size)); |
---|
| 524 | warn "$status" if $status ; |
---|
| 525 | |
---|
| 526 | $status = $image->ReadImage( |
---|
| 527 | $self->current_image->preview_file |
---|
| 528 | ); |
---|
[2661] | 529 | warn "$status" if $status; |
---|
| 530 | return $rval if $status; |
---|
[2597] | 531 | |
---|
[3177] | 532 | $self->current_image->preview_w( |
---|
| 533 | $image->Get('width') |
---|
| 534 | ); |
---|
| 535 | $self->current_image->preview_h( |
---|
| 536 | $image->Get('height') |
---|
| 537 | ); |
---|
| 538 | |
---|
| 539 | |
---|
[2597] | 540 | $status = $image->Thumbnail( |
---|
| 541 | geometry=>sprintf("%s%s>", $size*$size, '@') |
---|
| 542 | ); |
---|
[2661] | 543 | warn "$status" if $status; |
---|
| 544 | return $rval if $status; |
---|
[2597] | 545 | |
---|
[3241] | 546 | # causes strange behaviour with i18n -> yellow borders when local is other than EN |
---|
| 547 | # $status = $image->Set(background=>"white"); |
---|
| 548 | # warn "$status" if $status ; |
---|
[2597] | 549 | |
---|
[2618] | 550 | $status = $image->Set(Gravity=>"Center"); |
---|
| 551 | warn "$status" if $status ; |
---|
[2597] | 552 | |
---|
| 553 | $image->Extent( |
---|
| 554 | geometry=>sprintf("%sx%s", $size, $size), |
---|
| 555 | gravity=>'center', |
---|
| 556 | ); |
---|
| 557 | |
---|
[3177] | 558 | $image->Set( |
---|
| 559 | quality=>$self->wx_quality |
---|
| 560 | ); |
---|
[2597] | 561 | |
---|
| 562 | $status = $image->Strip(); |
---|
| 563 | warn "$status" if $status ; |
---|
[2696] | 564 | |
---|
[2597] | 565 | |
---|
| 566 | $image->Write( |
---|
| 567 | sprintf( |
---|
| 568 | "%s:%s", |
---|
| 569 | $self->type, |
---|
[3226] | 570 | encode('iso-8859-1', $self->current_image->wx_thumb_file), |
---|
[2597] | 571 | ) |
---|
| 572 | ); |
---|
| 573 | |
---|
| 574 | undef $image; |
---|
[2661] | 575 | |
---|
| 576 | $rval = 1; |
---|
| 577 | |
---|
| 578 | return $rval; |
---|
[2597] | 579 | } |
---|
| 580 | |
---|
| 581 | |
---|
| 582 | sub CreateGUIPreview { |
---|
| 583 | my ( $self ) = @_; |
---|
[3177] | 584 | printf("CreateGUIPreview %s\n", $self->current_image->preview_file ); |
---|
[2597] | 585 | return 1 if( -e $self->current_image->preview_file ); |
---|
[2661] | 586 | |
---|
| 587 | my $rval = 1; |
---|
[2597] | 588 | |
---|
[2661] | 589 | my $image = Image::Magick->new(); |
---|
[2597] | 590 | |
---|
| 591 | my $ratio = $self->preview_ratio; |
---|
| 592 | |
---|
[2661] | 593 | |
---|
| 594 | my $status = $image->Read( |
---|
[3142] | 595 | sprintf( |
---|
[3177] | 596 | "%s", |
---|
[3142] | 597 | $self->current_image->file, |
---|
| 598 | ) |
---|
[2597] | 599 | ); |
---|
[2661] | 600 | warn "$status ", $self->current_image->file, "\n" if $status ; |
---|
| 601 | return 0 if $status; |
---|
[2597] | 602 | |
---|
| 603 | $status = $image->Thumbnail( |
---|
| 604 | geometry=>sprintf( |
---|
| 605 | "%s%%x%s%%>", |
---|
| 606 | $ratio, |
---|
| 607 | $ratio |
---|
| 608 | ) |
---|
| 609 | ); |
---|
| 610 | warn "$status" if $status ; |
---|
[2661] | 611 | return 0 if $status; |
---|
[2597] | 612 | |
---|
| 613 | |
---|
| 614 | $status = $image->Set(background=>"white"); |
---|
| 615 | warn "$status" if $status ; |
---|
| 616 | |
---|
| 617 | $status = $image->Set(Gravity=>"Center"); |
---|
| 618 | warn "$status" if $status ; |
---|
| 619 | |
---|
| 620 | |
---|
[3177] | 621 | $image->Set(quality=>$self->wx_quality); |
---|
[2597] | 622 | |
---|
| 623 | |
---|
[2661] | 624 | $status = $image->Write( |
---|
[2597] | 625 | sprintf( |
---|
| 626 | "%s:%s", |
---|
| 627 | $self->type, |
---|
[3226] | 628 | encode('iso-8859-1', $self->current_image->preview_file), |
---|
[2597] | 629 | ) |
---|
| 630 | ); |
---|
[2661] | 631 | warn "$status" if $status ; |
---|
| 632 | return 0 if $status; |
---|
[2597] | 633 | |
---|
| 634 | undef $image; |
---|
| 635 | |
---|
[2661] | 636 | return $rval; |
---|
[2597] | 637 | } |
---|
| 638 | |
---|
| 639 | |
---|
| 640 | sub CreateResized { |
---|
| 641 | my ( $self ) = @_; |
---|
| 642 | |
---|
[2661] | 643 | my $rval = 1 ; |
---|
| 644 | return $rval if( -e $self->current_image->site_resized_file ); |
---|
[2597] | 645 | |
---|
[3177] | 646 | printf( |
---|
| 647 | "Create resized %s\n", |
---|
| 648 | $self->current_image->file, |
---|
| 649 | ); |
---|
[3142] | 650 | |
---|
[2597] | 651 | my $image = new Image::Magick; |
---|
| 652 | |
---|
| 653 | my $status = $image->ReadImage( |
---|
| 654 | $self->current_image->file |
---|
| 655 | ); |
---|
| 656 | warn "$status" if $status ; |
---|
[2661] | 657 | return 0 if $status; |
---|
[2597] | 658 | |
---|
| 659 | my $w = $image->Get('width'); |
---|
| 660 | my $h = $image->Get('height'); |
---|
| 661 | |
---|
| 662 | # should calculate the aspect ratio |
---|
| 663 | my $resize_w = $self->resize_w; |
---|
| 664 | my $resize_h = $self->resize_h; |
---|
| 665 | |
---|
| 666 | if( $w < $h ){ |
---|
| 667 | my $resize_w_ = $resize_w; |
---|
| 668 | $resize_w = $resize_h; |
---|
| 669 | $resize_h = $resize_w_; |
---|
| 670 | } |
---|
| 671 | |
---|
| 672 | $status = $image->Resize( |
---|
| 673 | geometry => sprintf("%sx%s>", $resize_w, $resize_h), |
---|
| 674 | filter => sprintf("%s", $self->filter), |
---|
| 675 | blur => $self->blur |
---|
| 676 | ); |
---|
| 677 | warn "$status" if $status ; |
---|
[2661] | 678 | return 0 if $status; |
---|
[2597] | 679 | |
---|
| 680 | $status = $image->Set(Gravity=>"Center"); |
---|
| 681 | warn "$status" if $status ; |
---|
| 682 | |
---|
[2730] | 683 | # exif from original image |
---|
| 684 | my $orientation = $self->current_image->exif_metadata->{Orientation}; |
---|
| 685 | |
---|
| 686 | # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW |
---|
| 687 | if( $orientation =~ m/Rotate (\d+)/ ){ |
---|
| 688 | printf( |
---|
| 689 | "Rotate %s\n", |
---|
| 690 | $1 |
---|
| 691 | ); |
---|
| 692 | |
---|
| 693 | $image->Rotate( degrees=>$1 ); |
---|
| 694 | } |
---|
[2696] | 695 | |
---|
[2597] | 696 | $status = $image->Set(quality=>$self->quality); |
---|
| 697 | warn "$status" if $status ; |
---|
| 698 | |
---|
[3177] | 699 | $status = $image->Set(interlace=>$self->interlace); |
---|
[3142] | 700 | warn "$status" if $status ; |
---|
| 701 | |
---|
[2597] | 702 | $image->Write( |
---|
| 703 | sprintf( |
---|
| 704 | "%s:%s", |
---|
| 705 | $self->type, |
---|
[3226] | 706 | encode('iso-8859-1', $self->current_image->site_resized_file), |
---|
[2597] | 707 | ) |
---|
| 708 | ); |
---|
[2661] | 709 | warn "$status" if $status ; |
---|
| 710 | return 0 if $status; |
---|
[2597] | 711 | |
---|
| 712 | undef $image; |
---|
| 713 | |
---|
[2661] | 714 | |
---|
| 715 | $rval = 0 if $status; |
---|
| 716 | |
---|
| 717 | return $rval; |
---|
[2597] | 718 | } |
---|
| 719 | |
---|
| 720 | sub CreateThumbnail { |
---|
| 721 | my ( $self ) = @_; |
---|
| 722 | |
---|
| 723 | return 1 if( -e $self->current_image->site_thumb_file ); |
---|
[2661] | 724 | |
---|
| 725 | my $rval = 1; |
---|
[2597] | 726 | |
---|
| 727 | my $image = new Image::Magick; |
---|
| 728 | |
---|
| 729 | my $status = $image->ReadImage( |
---|
[3226] | 730 | encode('iso-8859-1', $self->current_image->site_resized_file) |
---|
[2597] | 731 | ); |
---|
| 732 | warn "$status" if $status ; |
---|
| 733 | |
---|
| 734 | |
---|
| 735 | $status = $image->Resize( |
---|
| 736 | geometry => sprintf( |
---|
| 737 | "%sx%s>", |
---|
| 738 | $self->thumb_size, |
---|
| 739 | $self->thumb_size |
---|
| 740 | ), |
---|
| 741 | ); |
---|
| 742 | warn "$status" if $status ; |
---|
| 743 | |
---|
| 744 | $status = $image->Set(Gravity=>"Center"); |
---|
| 745 | warn "$status" if $status ; |
---|
| 746 | |
---|
[3177] | 747 | $status = $image->Set(quality=>$self->th_quality); |
---|
[2597] | 748 | warn "$status" if $status ; |
---|
| 749 | |
---|
| 750 | $status = $image->Strip(); |
---|
| 751 | warn "$status" if $status ; |
---|
| 752 | |
---|
| 753 | |
---|
| 754 | $image->Write( |
---|
| 755 | sprintf( |
---|
| 756 | "%s:%s", |
---|
| 757 | $self->type, |
---|
[3226] | 758 | encode('iso-8859-1', $self->current_image->site_thumb_file), |
---|
[2597] | 759 | ) |
---|
| 760 | ); |
---|
| 761 | |
---|
| 762 | undef $image; |
---|
| 763 | |
---|
[2661] | 764 | |
---|
| 765 | $rval = 0 if $status; |
---|
| 766 | |
---|
| 767 | return $rval; |
---|
[2597] | 768 | } |
---|
| 769 | |
---|
| 770 | |
---|
| 771 | |
---|
| 772 | sub _select_exif_data { |
---|
| 773 | my ( $self, $exif ) = @_; |
---|
| 774 | |
---|
| 775 | return { |
---|
| 776 | map { |
---|
| 777 | $_ => $exif->{$_}, |
---|
| 778 | } |
---|
| 779 | qw/ |
---|
| 780 | CreateDate |
---|
| 781 | ImageWidth |
---|
| 782 | ImageHeight |
---|
| 783 | Orientation |
---|
| 784 | DateTimeOriginal |
---|
| 785 | ISO |
---|
[2661] | 786 | ExposureTime |
---|
[2597] | 787 | ApertureValue |
---|
| 788 | FocalLength |
---|
| 789 | Lens |
---|
| 790 | Exposure |
---|
| 791 | Make |
---|
| 792 | Model |
---|
| 793 | / |
---|
| 794 | }; |
---|
| 795 | } |
---|
| 796 | |
---|
| 797 | sub Store { |
---|
| 798 | my ( $self ) = @_; |
---|
| 799 | |
---|
| 800 | my $data = $self->get_storable( |
---|
| 801 | [ |
---|
| 802 | qw/ |
---|
| 803 | images |
---|
| 804 | thumb_size |
---|
| 805 | preview_ratio |
---|
| 806 | type |
---|
| 807 | filter |
---|
| 808 | blur |
---|
| 809 | quality |
---|
[3177] | 810 | wx_quality |
---|
| 811 | th_quality |
---|
[2597] | 812 | prefix |
---|
| 813 | author |
---|
| 814 | count |
---|
| 815 | resize_w |
---|
| 816 | resize_h |
---|
| 817 | new_files |
---|
| 818 | storable_file |
---|
| 819 | wx_thumb_size |
---|
| 820 | current_image |
---|
| 821 | exif_metadata |
---|
| 822 | wx_thumb_dir |
---|
| 823 | preview_dir |
---|
| 824 | site_resized_dir |
---|
| 825 | site_thumb_dir |
---|
| 826 | userdata_dir |
---|
| 827 | progress_msg |
---|
[3267] | 828 | default_photo_name |
---|
[2597] | 829 | default_name_prefix |
---|
[2696] | 830 | upload_high |
---|
[3286] | 831 | remove_uploaded_from_selection |
---|
[3177] | 832 | auto_rotate |
---|
| 833 | interlace |
---|
| 834 | create_resized |
---|
| 835 | use_exif_preview |
---|
[3226] | 836 | image_sums |
---|
| 837 | sums |
---|
| 838 | version |
---|
| 839 | imagelist_version |
---|
[2597] | 840 | / |
---|
| 841 | ] |
---|
| 842 | |
---|
| 843 | ); |
---|
| 844 | eval { |
---|
| 845 | store $data, $self->storable_file; |
---|
| 846 | }; |
---|
| 847 | if($@){ |
---|
| 848 | print $@, "\n"; |
---|
| 849 | } |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | |
---|
| 853 | |
---|
| 854 | sub UploadSelection { |
---|
| 855 | my ( $self ) = @_; |
---|
| 856 | |
---|
| 857 | my $viewer_callback = $self->UploadImagesViewerCallback ; |
---|
| 858 | |
---|
| 859 | |
---|
| 860 | $self->upload_rejects( |
---|
| 861 | [] |
---|
| 862 | ); |
---|
| 863 | |
---|
[2728] | 864 | my $count = 1; |
---|
| 865 | my $msg; |
---|
[2696] | 866 | $self->count( |
---|
| 867 | $count |
---|
| 868 | ); |
---|
[2728] | 869 | my $uploaded = 0; |
---|
| 870 | my $rejected = 0; |
---|
| 871 | my $time_begin = time; |
---|
[2730] | 872 | my $last_error; |
---|
[2597] | 873 | map { |
---|
| 874 | # current image object |
---|
| 875 | $self->current_image( |
---|
[3226] | 876 | $self->GetImage($_) |
---|
[2597] | 877 | ); |
---|
[2661] | 878 | |
---|
| 879 | my ( $vol, $dir, $file ) = File::Spec->splitpath( |
---|
| 880 | $self->current_image->file |
---|
| 881 | ); |
---|
[2728] | 882 | |
---|
| 883 | my $site_name = $self->current_image->site_name; |
---|
[2661] | 884 | |
---|
[3226] | 885 | # my ( $filename, $ext ) = split /\./, $file ; |
---|
| 886 | my $filename = $self->current_image->file_sum ; |
---|
[2661] | 887 | |
---|
[2728] | 888 | # lately defined to make sure we have the last global properties ( resize_w, resize_h ) |
---|
[2661] | 889 | $self->current_image->site_resized_file( |
---|
| 890 | File::Spec->catfile( |
---|
| 891 | $self->site_resized_dir, |
---|
| 892 | sprintf( |
---|
| 893 | "%s_%sx%s.%s", |
---|
| 894 | $filename, |
---|
| 895 | $self->resize_w, |
---|
| 896 | $self->resize_h, |
---|
| 897 | $self->type, |
---|
| 898 | ) |
---|
| 899 | ) |
---|
| 900 | ); |
---|
[2728] | 901 | |
---|
| 902 | $msg = sprintf( |
---|
| 903 | "Preparing resized image for %s - %s", |
---|
| 904 | $site_name, |
---|
| 905 | $file, |
---|
| 906 | ); |
---|
[2597] | 907 | |
---|
[3231] | 908 | eval { |
---|
[2728] | 909 | # set current image thumbnail |
---|
| 910 | $self->progress_thumbnail_refresh->(); |
---|
| 911 | |
---|
| 912 | $self->progress_msg_refresh->($msg); |
---|
[2696] | 913 | |
---|
[2728] | 914 | # update upload progress dialog |
---|
[3360] | 915 | $self->progressbar_refresh->(0.20); |
---|
[3231] | 916 | }; |
---|
[2728] | 917 | # user cancelled : dialog box is destroyed |
---|
[3226] | 918 | croak "Upload cancelled. ", $@ if $@ ; |
---|
[3231] | 919 | |
---|
[3177] | 920 | if( $self->create_resized ){ |
---|
[3231] | 921 | eval { |
---|
[3177] | 922 | if(!$self->CreateResized()){ |
---|
| 923 | printf("CreateResized failed %s. Use ResizeCallback\n", $@); |
---|
| 924 | # use method provided by the caller |
---|
| 925 | # source, target, type, ratio, width, $height |
---|
| 926 | $self->ResizeCallback->( |
---|
| 927 | $self->current_image->file, |
---|
| 928 | $self->current_image->site_resized_file, |
---|
| 929 | $self->type, |
---|
| 930 | undef, |
---|
| 931 | $self->resize_w, |
---|
| 932 | $self->resize_h, |
---|
| 933 | $self->quality, |
---|
| 934 | ); |
---|
[2730] | 935 | |
---|
[3177] | 936 | $self->RotateImage( |
---|
| 937 | $self->current_image->site_resized_file, |
---|
| 938 | ) if $self->auto_rotate; |
---|
| 939 | } |
---|
[3231] | 940 | }; |
---|
[3177] | 941 | $self->_set_exif_tag( |
---|
| 942 | $self->current_image->site_resized_file, |
---|
| 943 | 'Orientation', |
---|
| 944 | 'Horizontal (normal)', |
---|
| 945 | ) if $self->auto_rotate; |
---|
| 946 | } |
---|
| 947 | # the original is at the right size, no need to create a resize |
---|
| 948 | else { |
---|
| 949 | $self->current_image->site_resized_file( |
---|
| 950 | $self->current_image->file, |
---|
| 951 | ); |
---|
| 952 | } |
---|
[2696] | 953 | |
---|
| 954 | |
---|
| 955 | |
---|
[2728] | 956 | # if upload high, rotate a copy of original file |
---|
| 957 | if($self->upload_high){ |
---|
| 958 | $self->CreateHigh(); |
---|
[2661] | 959 | } |
---|
[2597] | 960 | |
---|
[2728] | 961 | $msg = sprintf( |
---|
| 962 | "Preparing thumbnail for %s - %s", |
---|
| 963 | $site_name, |
---|
| 964 | $file, |
---|
[2597] | 965 | ); |
---|
[2696] | 966 | |
---|
[3231] | 967 | eval { |
---|
[2728] | 968 | $self->progress_msg_refresh->($msg); |
---|
[3231] | 969 | }; |
---|
[3226] | 970 | croak "Upload cancelled. ", $@ if $@ ; |
---|
[2728] | 971 | |
---|
[3231] | 972 | eval { |
---|
[2661] | 973 | $self->CreateThumbnail(); |
---|
[3231] | 974 | }; |
---|
[2728] | 975 | |
---|
[2661] | 976 | if($@){ |
---|
[2728] | 977 | $msg = sprintf( |
---|
| 978 | "An error has occured %s - %s\n$@", |
---|
| 979 | $site_name, |
---|
| 980 | $file |
---|
[2661] | 981 | ); |
---|
| 982 | } |
---|
| 983 | else{ |
---|
[2728] | 984 | $msg = sprintf( |
---|
| 985 | "Uploading %s - %s", |
---|
| 986 | $site_name, |
---|
| 987 | $file |
---|
[2661] | 988 | ); |
---|
| 989 | } |
---|
[3231] | 990 | eval { |
---|
[2728] | 991 | $self->progress_msg_refresh->($msg); |
---|
| 992 | $self->progressbar_refresh->(0.50); |
---|
[3231] | 993 | }; |
---|
[3226] | 994 | croak "Upload cancelled. ", $@ if $@ ; |
---|
[2661] | 995 | |
---|
[2696] | 996 | # photo metadata |
---|
[2661] | 997 | $self->_prepare_upload_properties(); |
---|
[2597] | 998 | my ( $status, $status_msg ) = $self->pwg->UploadImage(); |
---|
| 999 | |
---|
| 1000 | if ( $status ){ |
---|
[2728] | 1001 | $msg = sprintf( |
---|
| 1002 | "%s : %s upload succcessful.", |
---|
| 1003 | $site_name, |
---|
| 1004 | $file |
---|
[2597] | 1005 | ); |
---|
[3286] | 1006 | |
---|
[2728] | 1007 | $uploaded++; |
---|
[2597] | 1008 | } else { |
---|
[2728] | 1009 | $msg = sprintf( |
---|
| 1010 | "An error has occured.\n%s : %s upload is cancelled.\n$status_msg", |
---|
| 1011 | $site_name, |
---|
| 1012 | $file |
---|
[2597] | 1013 | ); |
---|
[2728] | 1014 | $rejected++; |
---|
[2730] | 1015 | $last_error = $status_msg; |
---|
[2597] | 1016 | } |
---|
[2696] | 1017 | |
---|
| 1018 | $count++; |
---|
[2597] | 1019 | $self->count( |
---|
[2696] | 1020 | $count |
---|
[2597] | 1021 | ); |
---|
| 1022 | # update upload progress dialog |
---|
[3231] | 1023 | eval { |
---|
[2728] | 1024 | $self->progress_msg_refresh->($msg); |
---|
| 1025 | $self->progressbar_refresh->(1); |
---|
[3231] | 1026 | }; |
---|
[3226] | 1027 | croak "Upload cancelled. ", $@ if $@ ; |
---|
[2597] | 1028 | |
---|
| 1029 | } |
---|
[2618] | 1030 | @{$self->image_selection} if defined |
---|
| 1031 | $self->image_selection; |
---|
[2728] | 1032 | |
---|
| 1033 | my $time_end = time; |
---|
[2729] | 1034 | my $duration = $time_end - $time_begin; |
---|
[2728] | 1035 | $msg = sprintf( |
---|
[2730] | 1036 | "%s images processed\n\n%s images uploaded\n\n%s images in errors and not uploaded - $last_error\n\nDuration : %s seconds", |
---|
[2728] | 1037 | $self->count - 1, |
---|
| 1038 | $uploaded, |
---|
| 1039 | $rejected, |
---|
| 1040 | $duration, |
---|
| 1041 | ); |
---|
| 1042 | $self->progress_endinfo_refresh->($msg); |
---|
| 1043 | } |
---|
| 1044 | |
---|
| 1045 | # if we need to rotate |
---|
| 1046 | sub CreateHigh { |
---|
| 1047 | my ( $self ) = @_; |
---|
| 1048 | |
---|
| 1049 | my $orientation = $self->current_image->exif_metadata->{Orientation}; |
---|
| 1050 | |
---|
| 1051 | # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW |
---|
[3177] | 1052 | if( $self->auto_rotate and $orientation =~ m/Rotate (\d+)/ ){ |
---|
[2728] | 1053 | |
---|
| 1054 | my ( $vol, $dir, $file ) = File::Spec->splitpath( |
---|
| 1055 | $self->current_image->file |
---|
| 1056 | ); |
---|
| 1057 | |
---|
| 1058 | my ( $filename, $ext ) = split /\./, $file ; |
---|
| 1059 | |
---|
| 1060 | # high_file is a copy of original |
---|
| 1061 | $self->current_image->site_high_file( |
---|
| 1062 | File::Spec->catfile( |
---|
| 1063 | $self->site_resized_dir, |
---|
| 1064 | sprintf( |
---|
| 1065 | "%s_high.%s", |
---|
| 1066 | $filename, |
---|
| 1067 | $self->type, |
---|
| 1068 | ) |
---|
| 1069 | ) |
---|
| 1070 | ); |
---|
| 1071 | |
---|
| 1072 | my $image = Image::Magick->new(); |
---|
| 1073 | # we read original |
---|
| 1074 | my $status = $image->Read( |
---|
| 1075 | $self->current_image->file |
---|
| 1076 | ); |
---|
| 1077 | warn "$status ", $self->current_image->file, "\n" if $status ; |
---|
| 1078 | return 0 if $status; |
---|
| 1079 | |
---|
| 1080 | $image->Rotate( degrees=>$1 ); |
---|
[2696] | 1081 | |
---|
[2728] | 1082 | $image->Write( |
---|
[3231] | 1083 | filename=>encode('iso-8859-1', $self->current_image->site_high_file) |
---|
[2728] | 1084 | ); |
---|
| 1085 | warn "$status ", $self->current_image->site_high_file, "\n" if $status ; |
---|
| 1086 | return 0 if $status; |
---|
| 1087 | |
---|
| 1088 | undef $image; |
---|
| 1089 | |
---|
| 1090 | $self->_set_exif_tag( |
---|
| 1091 | $self->current_image->site_high_file, |
---|
| 1092 | 'Orientation', |
---|
| 1093 | 'Horizontal (normal)', |
---|
| 1094 | ); |
---|
| 1095 | |
---|
| 1096 | # Now all images that need to be rotated are done. Update exif |
---|
| 1097 | $self->current_image->exif_metadata->{Orientation} = 'Horizontal (normal)'; |
---|
| 1098 | } |
---|
| 1099 | else{ |
---|
| 1100 | # high file is the original file |
---|
| 1101 | $self->current_image->site_high_file( |
---|
| 1102 | $self->current_image->file |
---|
| 1103 | ); |
---|
| 1104 | } |
---|
| 1105 | |
---|
| 1106 | return 1; |
---|
[2597] | 1107 | } |
---|
| 1108 | |
---|
[2661] | 1109 | sub _prepare_upload_properties { |
---|
[2597] | 1110 | my ( $self ) = @_; |
---|
| 1111 | |
---|
[2696] | 1112 | $self->pwg->upload_high( |
---|
| 1113 | $self->upload_high |
---|
| 1114 | ); |
---|
| 1115 | |
---|
| 1116 | $self->pwg->site_high_file( |
---|
| 1117 | $self->current_image->site_high_file |
---|
| 1118 | ); |
---|
| 1119 | |
---|
| 1120 | $self->pwg->site_resized_file( |
---|
[2597] | 1121 | $self->current_image->site_resized_file |
---|
| 1122 | ); |
---|
| 1123 | |
---|
[2696] | 1124 | $self->pwg->site_thumb_file( |
---|
[2597] | 1125 | $self->current_image->site_thumb_file |
---|
| 1126 | ); |
---|
| 1127 | |
---|
[2696] | 1128 | $self->pwg->site_author( |
---|
[2597] | 1129 | $self->current_image->site_author |
---|
| 1130 | ); |
---|
| 1131 | |
---|
[2696] | 1132 | $self->pwg->site_comment( |
---|
[2597] | 1133 | $self->current_image->site_comment |
---|
| 1134 | ); |
---|
| 1135 | |
---|
[2696] | 1136 | $self->pwg->site_image_name( |
---|
[2597] | 1137 | $self->current_image->site_name |
---|
| 1138 | ); |
---|
| 1139 | |
---|
[2696] | 1140 | $self->pwg->site_img_date_creation( |
---|
[2597] | 1141 | $self->current_image->create_date |
---|
| 1142 | ); |
---|
| 1143 | |
---|
| 1144 | $self->current_image->site_categories( |
---|
| 1145 | $self->categories |
---|
| 1146 | ); |
---|
| 1147 | |
---|
| 1148 | $self->pwg->categories( |
---|
| 1149 | sprintf( |
---|
| 1150 | "%s", |
---|
| 1151 | join(';', @{$self->categories}) |
---|
| 1152 | ) |
---|
| 1153 | ); |
---|
| 1154 | |
---|
| 1155 | $self->pwg->tags( |
---|
| 1156 | #join(',', @{$self->current_image->site_tags}) |
---|
| 1157 | ); |
---|
| 1158 | |
---|
| 1159 | } |
---|
| 1160 | |
---|
[2696] | 1161 | # read Orientation exif tag from original image |
---|
| 1162 | # apply rotation to image ( preview or resize ) |
---|
| 1163 | sub RotateImage { |
---|
| 1164 | my ( $self, $file ) = @_; |
---|
| 1165 | |
---|
[2728] | 1166 | # exif from original image |
---|
[2696] | 1167 | my $orientation = $self->current_image->exif_metadata->{Orientation}; |
---|
| 1168 | |
---|
| 1169 | # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW |
---|
| 1170 | if( $orientation =~ m/Rotate (\d+)/ ){ |
---|
| 1171 | printf( |
---|
| 1172 | "Rotate %s\n", |
---|
| 1173 | $1 |
---|
| 1174 | ); |
---|
[2597] | 1175 | |
---|
[2696] | 1176 | my $image = Image::Magick->new(); |
---|
[2728] | 1177 | |
---|
| 1178 | # read resized file |
---|
[2696] | 1179 | my $status = $image->Read( |
---|
| 1180 | $file |
---|
| 1181 | ); |
---|
| 1182 | warn "$status ", $file, "\n" if $status ; |
---|
| 1183 | return 0 if $status; |
---|
| 1184 | |
---|
| 1185 | $image->Rotate( degrees=>$1 ); |
---|
| 1186 | |
---|
[2728] | 1187 | # write resizd file |
---|
[2696] | 1188 | $image->Write( |
---|
[3231] | 1189 | filename=>encode('iso-8859-1', $file) |
---|
[2696] | 1190 | ); |
---|
| 1191 | warn "$status ", $file, "\n" if $status ; |
---|
| 1192 | return 0 if $status; |
---|
| 1193 | |
---|
| 1194 | undef $image; |
---|
| 1195 | |
---|
| 1196 | } |
---|
| 1197 | return 1; |
---|
| 1198 | } |
---|
| 1199 | |
---|
[3226] | 1200 | sub GetImage { |
---|
| 1201 | my ( $self, $indx ) = @_; |
---|
| 1202 | |
---|
| 1203 | my $sum = $self->sums->[$indx]; |
---|
| 1204 | |
---|
| 1205 | $self->image_sums->{$sum}; |
---|
| 1206 | } |
---|
| 1207 | |
---|
[3366] | 1208 | sub DeleteImage { |
---|
| 1209 | my ( $self, $indx ) = @_; |
---|
| 1210 | |
---|
| 1211 | my $sum = $self->sums->[$indx]; |
---|
| 1212 | |
---|
| 1213 | delete $self->image_sums->{$sum}; |
---|
| 1214 | } |
---|
| 1215 | |
---|
| 1216 | |
---|
[2597] | 1217 | 1; |
---|