Changeset 4747 for extensions/pLoader
- Timestamp:
- Jan 26, 2010, 8:15:55 AM (14 years ago)
- Location:
- extensions/pLoader/trunk/src/Uploader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/pLoader/trunk/src/Uploader/ImageList.pm
r4724 r4747 81 81 progressbar_refresh 82 82 progress_endinfo_refresh 83 RescaleCallback84 83 ResizeCallback 85 84 upload_rejects … … 159 158 160 159 sub _set_exif_tag { 161 my ( $self, $file, $tag, $newValue ) = @_; 160 my ( $self, $file, $tag, $newValue ) = @_; 162 161 163 162 my $options = {}; … … 195 194 196 195 $self->current_image->site_thumb_file( 197 File::Spec->catfile( 198 $self->site_thumb_dir, 199 $filename 196 sprintf("%s.%s", 197 File::Spec->catfile( 198 $self->site_thumb_dir, 199 'thumbnail' 200 ), 201 $self->type 200 202 ) 201 203 ); … … 205 207 206 208 sub SetCurrentImage { 207 my ( $self, $indx ) = @_; 209 my ( $self, $indx ) = @_; 208 210 209 211 $self->current_image( … … 226 228 227 229 map { 228 229 my $is_new_image = $self->_add_image($_, $info, $i);230 my $info = $self->_read_exif_metatdata($_->{ANSIPathName}); 231 my $is_new_image = $self->_add_image($_, $info, $i); 230 232 $self->SetCurrentImage($i); 231 233 $self->_set_current_image_filepaths(); 232 234 233 235 if($is_new_image){ 234 235 236 #my $use_wx_resize = $self->_create_gui_preview($info); 237 $self->_create_gui_thumbnail(); 236 238 237 239 # ok … … 284 286 # key is file path 285 287 sub _add_image { 286 my ( $self, $file, $info, $i ) = @_; 288 my ( $self, $file, $info, $i ) = @_; 287 289 288 290 my $is_new_image; … … 340 342 my $chrono = join('', $yyyy, $mm, $dd); 341 343 if('Prefix' eq $self->default_photo_name){ 342 344 $name = $self->default_name_prefix 343 345 } 344 346 elsif('File name' eq $self->default_photo_name){ 345 347 $name = $filename 346 348 } 347 349 elsif('File path and name' eq $self->default_photo_name){ … … 349 351 "%s", 350 352 File::Spec->catfile($path, $filename), 351 ) 352 } 353 ) 354 } 353 355 elsif('Prefix + rank number' eq $self->default_photo_name){ 354 356 $name = sprintf( … … 356 358 $self->default_name_prefix, 357 359 1+$i, 358 ) 359 } 360 ) 361 } 360 362 elsif('Rank number + prefix' eq $self->default_photo_name){ 361 363 $name = sprintf( … … 363 365 1+$i, 364 366 $self->default_name_prefix, 365 ) 366 } 367 ) 368 } 367 369 elsif('Prefix + create date chrono' eq $self->default_photo_name){ 368 370 $name = sprintf( … … 370 372 $self->default_name_prefix, 371 373 $chrono, 372 ) 373 } 374 ) 375 } 374 376 elsif('Create date chrono + prefix' eq $self->default_photo_name){ 375 377 $name = sprintf( … … 377 379 $chrono, 378 380 $self->default_name_prefix, 379 ) 381 ) 380 382 } 381 383 … … 388 390 389 391 eval { 390 printf("create gui thumbnail\n");391 # use the preview image to create a gui display thumbnail392 392 if(!$self->CreateGUIThumbnail()) 393 393 { 394 print "CreateGUIThumbnail failed, use callback\n";395 394 $self->ResizeCallback->( 396 395 $self->current_image->file, … … 401 400 $self->wx_quality, 402 401 ); 403 402 404 403 } 405 404 }; … … 440 439 splice @{$self->sums}, $index, 1 ; 441 440 $self->wx_thumb_imglist->Remove($index); 442 441 443 442 } 444 443 … … 447 446 my ( $self ) = @_; 448 447 449 # return 1 if( -e $self->current_image->wx_thumb_file );450 448 my $rval = 0; 451 print "CreateGUIThumbnail ", $self->current_image->wx_thumb_file, "\n";452 449 my $image = new Image::Magick; 453 450 … … 471 468 472 469 473 470 # maximize size and keep aspect ratio 474 471 $status = $image->Thumbnail( 475 472 geometry=>sprintf("%s%s>", $size*$size, '@') … … 493 490 gravity=>'center', 494 491 ); 495 492 496 493 $image->Set( 497 494 quality=>$self->wx_quality||90 … … 511 508 ); 512 509 513 $image->Rotate( degrees=>$1 ) if $self->auto_rotate; 510 $image->Rotate( degrees=>$1 ) if $self->auto_rotate; 514 511 } 515 512 … … 537 534 538 535 my $rval = 1 ; 539 #return $rval if( -e $self->current_image->site_resized_file ); 540 541 printf( 542 "Create resized %s\n", 543 $self->current_image->file, 544 ); 536 545 537 546 538 my $image = new Image::Magick; … … 586 578 ); 587 579 588 $image->Rotate( degrees=>$1 ) if $self->auto_rotate; 580 $image->Rotate( degrees=>$1 ) if $self->auto_rotate; 589 581 } 590 582 … … 671 663 return { 672 664 map { 673 665 $_ => $exif->{$_}, 674 666 } 675 667 qw/ … … 698 690 qw/ 699 691 images 700 692 thumb_size 701 693 preview_ratio 702 703 704 705 706 707 708 709 710 694 type 695 filter 696 blur 697 quality 698 wx_quality 699 th_quality 700 prefix 701 author 702 count 711 703 resize_w 712 704 resize_h 713 714 715 705 hd_filter 706 hd_blur 707 hd_quality 716 708 hd_w 717 709 hd_h 718 710 hd_interlace 719 711 new_files 720 712 storable_file 721 713 wx_thumb_size 722 714 current_image 723 715 exif_metadata … … 728 720 progress_msg 729 721 default_photo_name 730 731 732 733 734 735 736 737 738 739 722 default_name_prefix 723 upload_high 724 upload_hd 725 remove_uploaded_from_selection 726 auto_rotate 727 interlace 728 create_resized 729 use_exif_preview 730 image_sums 731 sums 740 732 version 741 733 imagelist_version … … 748 740 watermark_x 749 741 watermark_color 750 751 752 753 742 reupload_action_files 743 reupload_action_properties 744 reupload_action_properties_m 745 display_mode 754 746 / 755 747 ] … … 760 752 }; 761 753 if($@){ 762 print $@, "\n"; 754 print $@, "\n"; 763 755 } 764 756 } … … 767 759 768 760 sub UploadSelection { 769 my ( $self ) = @_; 761 my ( $self ) = @_; 770 762 771 763 my $viewer_callback = $self->UploadImagesViewerCallback ; … … 784 776 $self->upload_begin_time(time); 785 777 $self->upload_selection_count(scalar @{$self->image_selection}); 786 778 # for re-upload management 787 779 $self->upload_image_sums( [ 788 789 790 791 792 793 794 795 796 797 798 780 map { $self->GetImage($_)->file_sum } 781 @{$self->image_selection} 782 ] 783 ); 784 785 # check if already exist on server 786 my $uploaded = $self->pwg->IsAlreadyUploaded($self->upload_image_sums); 787 my @already_uploaded = grep { $_ } values %$uploaded ; 788 $self->ReuploadCallback->() if ( scalar @already_uploaded and !$self->reupload_not_ask ); 789 790 799 791 foreach(@{$self->image_selection}) { 800 # current image object 801 802 803 792 # current image object 793 $self->current_image( 794 $self->GetImage($_) 795 ); 804 796 # prepare resized, high, thumbnail 805 797 # if not already uploaded 806 798 $self->_set_site_resized_file(); 807 799 $self-> _set_site_high_file (); 808 800 # photo metadata 809 801 $self->_upload_selection_prepare() if (!$uploaded->{$self->current_image->file_sum} or $self->reupload_action_files); 810 $self->_prepare_upload_properties(); 802 $self->_prepare_upload_properties(); 811 803 812 804 # transfert resized, high, thumbnail to site … … 817 809 1+$self->count 818 810 ); 811 # remove thumbnail, resized, HD files 812 # to make sure everything is clean 813 map{ 814 unlink $self->current_image->$_ if -e $self->current_image->$_; 815 } 816 qw/ site_resized_file site_high_file site_thumb_file/; 819 817 } 820 818 … … 848 846 } 849 847 850 848 my $decode = { 851 849 'No' => 0, 852 853 854 }; 850 'Yes, use HD resized of the original photo' => 'HD', 851 'Yes, use a copy of the original photo' => 'ORIGINAL', 852 }; 855 853 #printf("upload HD %s\n", $self->upload_hd); 856 857 858 854 $self->upload_high( 855 $decode->{$self->upload_hd} 856 ); 859 857 #printf("upload High %s\n", $self->upload_high); 860 858 861 859 # if upload high, rotate a copy of original file 862 860 if($self->upload_high){ … … 883 881 ); 884 882 # set current image thumbnail 885 883 # update upload progress dialog 886 884 #$self->progressbar_refresh->($value); 887 885 }; … … 970 968 1+$self->upload_rejected_count 971 969 ); 972 } 970 } 973 971 974 972 } … … 1020 1018 sprintf( 1021 1019 "%s_%sx%s.%s", 1022 $filename, 1020 # $filename, 1021 'resized', 1023 1022 $self->resize_w, 1024 1023 $self->resize_h, … … 1027 1026 ) 1028 1027 ); 1029 #printf("_set_site_resized_file %s\n", $self->current_image->site_resized_file);1028 printf("_set_site_resized_file %s\n", $self->current_image->site_resized_file); 1030 1029 } 1031 1030 … … 1035 1034 eval { 1036 1035 if(!$self->CreateResized()){ 1037 $self->_ _create_resized_fallback();1036 $self->_create_resized_fallback(); 1038 1037 }; 1039 1038 … … 1059 1058 my ( $self ) = @_; 1060 1059 # use wx builtin rescale if IM fails 1061 #printf("CreateResized failed %s. Use ResizeCallback\n", $@);1060 printf("CreateResized failed %s. Use ResizeCallback\n", $@); 1062 1061 # use method provided by the caller 1063 1062 # source, target, type, ratio, width, $height … … 1066 1065 $self->current_image->site_resized_file, 1067 1066 $self->type, 1068 undef,1069 1067 $self->resize_w, 1070 1068 $self->resize_h, … … 1085 1083 my $bRotate; 1086 1084 my $bAddWatermark; 1087 1085 my $bResize; 1088 1086 my $orientation = $self->current_image->exif_metadata->{Orientation}; 1089 1087 my $degrees; 1090 1088 1091 1089 # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW … … 1093 1091 $bModifyOriginal = 1; 1094 1092 $bRotate = 1; 1095 1093 $degrees = $1; 1096 1094 } 1097 1095 … … 1100 1098 $bAddWatermark = 1; 1101 1099 } 1102 1103 1104 1100 1101 # HD resize 1102 if('HD' eq $self->upload_high){ 1105 1103 $bModifyOriginal = 1; 1106 1104 $bResize = 1; 1107 1105 } 1108 1106 1109 1107 if($bModifyOriginal){ … … 1132 1130 $status = $image->Set(interlace=>$self->interlace); 1133 1131 warn "$status" if $status ; 1134 1132 1135 1133 if($bRotate){ 1136 $image->Rotate( degrees=>$degrees ); 1134 $image->Rotate( degrees=>$degrees ); 1137 1135 } 1138 1136 $image->Write( … … 1181 1179 1182 1180 # file name for original copy 1181 # we do not need the original file name 1183 1182 sub _set_site_high_file { 1184 1183 my ( $self ) = @_; … … 1195 1194 $self->site_resized_dir, 1196 1195 sprintf( 1197 "%s _high.%s",1198 $filename,1196 "%s.%s", 1197 'high_file', 1199 1198 $self->type, 1200 1199 ) … … 1245 1244 my ( $self ) = @_; 1246 1245 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1246 1247 $self->pwg->reupload_action_files( 1248 $self->reupload_action_files||1 1249 ); 1250 $self->pwg->reupload_action_properties( 1251 $self->reupload_action_properties||2 1252 ); 1253 1254 $self->pwg->reupload_action_properties_m( 1255 $self->reupload_action_properties_m||1 1256 ); 1258 1257 1259 1258 $self->pwg->upload_high( … … 1289 1288 ); 1290 1289 1291 1292 1293 1294 1290 $self->pwg->privacy_level( 1291 $self->current_image->privacy_level 1292 ); 1293 1295 1294 $self->current_image->site_categories( 1296 1295 $self->categories … … 1308 1307 ); 1309 1308 1310 1309 1311 1310 } 1312 1311 … … 1335 1334 return 0 if $status; 1336 1335 1337 $image->Rotate( degrees=>$1 ); 1336 $image->Rotate( degrees=>$1 ); 1338 1337 1339 1338 # write resized file … … 1346 1345 undef $image; 1347 1346 1348 } 1347 } 1349 1348 return 1; 1350 1349 } -
extensions/pLoader/trunk/src/Uploader/PWG/WebServices.pm
r4610 r4747 64 64 image_id 65 65 typecode 66 67 68 69 70 71 66 reupload_action_files 67 reupload_action_properties 68 reupload_action_properties_m 69 single_value_mode 70 multiple_value_mode 71 privacy_level 72 72 / 73 73 ); … … 83 83 file => 'file', 84 84 thumbnail => 'thumb', 85 high => 'high', 86 } 87 ); 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 85 high => 'high', 86 } 87 ); 88 89 $self->single_value_mode( 90 { 91 1 => 'fill_if_empty', 92 2 => 'replace', 93 } 94 ); 95 96 $self->multiple_value_mode( 97 { 98 1 => 'append', 99 2 => 'replace', 100 } 101 ); 102 103 103 $self->uagent( 104 104 LWP::UserAgent->new( … … 107 107 ); 108 108 109 $self->uagent->cookie_jar({}); 109 $self->uagent->cookie_jar({}); 110 110 111 111 $self->urlbase( … … 174 174 ); 175 175 }; 176 176 if($@){ 177 177 # when server response has warnings, the content response is not a valid json string 178 178 # find the json response 179 179 $self->uagent_response->content =~ /(\{.+\})/; 180 180 #printf("json response %s\n", $1); 181 181 eval { 182 182 $hresult = from_json( … … 184 184 ); 185 185 }; 186 } 186 } 187 187 } 188 188 else{ 189 189 $hresult = { 190 190 'message' => $self->uagent_response->message, 191 191 'stat' => 'fail', 192 192 }; 193 193 } 194 195 194 195 $hresult; 196 196 } 197 197 … … 203 203 $self->uagent->get( 204 204 $query 205 205 ) 206 206 ); 207 207 }; … … 211 211 $query, 212 212 $@, 213 ); 213 ); 214 214 } 215 215 } … … 226 226 ) 227 227 ); 228 228 }; 229 229 230 230 if($@){ … … 232 232 $form->{method}, 233 233 $@, 234 ); 234 ); 235 235 } 236 237 236 237 return ( $result->is_success, $result->status_line ); 238 238 } 239 239 sub GetCategories { … … 242 242 243 243 $self->_execute_get( 244 245 244 $self->qry_list_categories 245 ); 246 246 $self->_json_response_content->{result}{categories}; 247 247 } … … 251 251 252 252 $self->_execute_get( 253 $self->qry_list_tags 254 253 $self->qry_list_tags 254 ); 255 255 $self->_json_response_content->{result}{tags}; 256 256 } … … 295 295 } @types; 296 296 297 297 298 298 $form = { 299 299 method => 'pwg.images.add', … … 311 311 312 312 $form->{high_sum} = $self->sum->{high} if $self->upload_high; 313 313 314 314 $progress->{yield}->(); 315 315 ( $status, $status_line ) = $self->_execute_post($form); 316 316 } 317 317 # re-upload 318 318 else{ … … 323 323 my $files = $self->_check_files(); 324 324 if(defined($files)){ 325 $self->_add_files($files, $progress); 325 $self->_add_files($files, $progress); 326 326 } 327 327 } … … 330 330 method => 'pwg.images.setInfo', 331 331 image_id => $self->image_id, 332 332 }; 333 333 # update metadata info 334 if($self->reupload_action_properties){335 #printf("reupload_action_properties %s\n", $self->reupload_action_properties);334 # simple value metadata 335 if($self->reupload_action_properties){ 336 336 $form->{name} = $self->site_image_name; 337 337 $form->{author} = $self->site_author; 338 338 $form->{comment} = $self->site_comment; 339 339 $form->{date_creation} = $self->site_img_date_creation; 340 340 $form->{single_value_mode} = $self->single_value_mode->{$self->reupload_action_properties}; 341 341 $form->{level} = $self->privacy_level ? 2**($self->privacy_level - 1) : 0; 342 343 if($self->reupload_action_properties_m){344 #printf("reupload_action_properties_m %s\n", $self->reupload_action_properties_m); 342 } 343 # multi value metadata 344 if($self->reupload_action_properties_m){ 345 345 $form->{tag_ids} = $self->site_tags if $self->site_tags; 346 346 $form->{categories} = $self->categories; 347 347 $form->{multiple_value_mode} = $self->multiple_value_mode->{$self->reupload_action_properties_m}; 348 348 }; 349 349 $progress->{yield}->(); 350 350 ( $status, $status_line ) = $self->_execute_post($form); 351 351 352 352 } 353 353 354 354 delete $form->{tag_ids} unless defined $self->site_tags; … … 357 357 $progress->{yield}->(); 358 358 # for first upload 359 # make sure the image is uploaded by querying for its existence 359 360 if($doubleCheck){ 360 361 362 361 $self->image_id( 362 $self->_exists($progress->{original_sum}) 363 ); 363 364 $content->{stat} = !defined $self->image_id ? 'fail' : 'ok'; 364 365 if(defined $self->image_id and defined $self->privacy_level){ 365 366 367 } 368 369 366 ( $status, $status_line, $content ) = $self->_set_privacy_level; 367 } 368 } 369 370 last UPLOAD; 370 371 }# UPLOAD 371 372 … … 375 376 sub _set_privacy_level { 376 377 my ( $self ) = @_; 377 378 378 379 my $form = { 379 380 method => 'pwg.images.setPrivacyLevel', … … 381 382 level => $self->privacy_level ? 2**($self->privacy_level - 1) : 0, 382 383 }; 383 384 384 print Dumper $form; 385 my ( $status, $status_line ) = $self->_execute_post($form); 385 386 my $hresult = $self->_json_response_content; 386 387 … … 405 406 ); 406 407 407 high => $self->_checksum(408 $self->site_high_file,409 $progress410 ),411 412 408 $self->sum->{high} = $self->_checksum( 413 409 $self->site_high_file, … … 457 453 $self->typecode->{$_}; 458 454 } grep { 'equals' ne $files->{$_} } keys %$files ; 459 455 460 456 } 461 457 … … 472 468 image_id => $self->image_id, 473 469 type => $type_code, 474 sum => $self->sum->{$type_code}, 475 }; 470 sum => $self->sum->{$type_code}, 471 }; 476 472 477 473 $self->_execute_post($form); … … 485 481 sub IsAlreadyUploaded { 486 482 my ( $self, $md5_sums ) = @_; 487 488 489 483 484 # md5_sums is an array ref 485 $self->_execute_post({ 490 486 method => 'pwg.images.exist', 491 487 md5sum_list => join(',', @$md5_sums) 492 493 494 495 488 } 489 ); 490 491 my $sums = $self->_json_response_content->{result}; 496 492 497 493 $sums; … … 509 505 my $hresult = $self->_json_response_content; 510 506 511 507 $hresult->{result} = {} if 'HASH' ne ref $hresult->{result}; 512 508 my $id = 'ok' eq $hresult->{stat} ? $hresult->{result}{$md5_sum} : undef ; 513 509 … … 529 525 ) 530 526 ); 527 531 528 eval { 532 529 $file_sum = file_md5_hex( … … 581 578 582 579 }; 583 580 584 581 return ( $self->_execute_post($form), $self->_json_response_content ); 585 582 }
Note: See TracChangeset
for help on using the changeset viewer.