Changeset 4747 for extensions/pLoader


Ignore:
Timestamp:
Jan 26, 2010, 8:15:55 AM (14 years ago)
Author:
ronosman
Message:

Feature 1400 added : remove resized image file cache.

Location:
extensions/pLoader/trunk/src/Uploader
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/src/Uploader/ImageList.pm

    r4724 r4747  
    8181                progressbar_refresh
    8282                progress_endinfo_refresh
    83                 RescaleCallback
    8483                ResizeCallback
    8584                upload_rejects
     
    159158
    160159sub _set_exif_tag {
    161     my ( $self, $file, $tag, $newValue ) = @_; 
     160    my ( $self, $file, $tag, $newValue ) = @_;   
    162161
    163162  my $options = {};
     
    195194
    196195    $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
    200202        )
    201203    );
     
    205207
    206208sub SetCurrentImage {
    207     my ( $self, $indx ) = @_;   
     209    my ( $self, $indx ) = @_;   
    208210
    209211    $self->current_image(
     
    226228
    227229    map {
    228         my $info = $self->_read_exif_metatdata($_->{ANSIPathName});
    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);   
    230232        $self->SetCurrentImage($i);
    231         $self->_set_current_image_filepaths();
     233        $self->_set_current_image_filepaths();
    232234
    233235        if($is_new_image){
    234             #my $use_wx_resize = $self->_create_gui_preview($info);
    235             $self->_create_gui_thumbnail();
     236            #my $use_wx_resize = $self->_create_gui_preview($info);
     237            $self->_create_gui_thumbnail();
    236238
    237239            # ok
     
    284286# key is file path
    285287sub _add_image {
    286     my ( $self, $file, $info, $i ) = @_;       
     288    my ( $self, $file, $info, $i ) = @_;   
    287289
    288290    my $is_new_image;
     
    340342    my $chrono = join('', $yyyy, $mm, $dd);
    341343    if('Prefix' eq $self->default_photo_name){
    342         $name = $self->default_name_prefix
     344        $name = $self->default_name_prefix
    343345    }
    344346    elsif('File name' eq $self->default_photo_name){
    345         $name = $filename
     347        $name = $filename
    346348    }
    347349    elsif('File path and name' eq $self->default_photo_name){
     
    349351            "%s",
    350352            File::Spec->catfile($path, $filename),
    351         )       
    352     }   
     353        )       
     354    }   
    353355    elsif('Prefix + rank number' eq $self->default_photo_name){
    354356        $name = sprintf(
     
    356358            $self->default_name_prefix,
    357359            1+$i,
    358         )       
    359     }   
     360        )       
     361    }   
    360362    elsif('Rank number + prefix' eq $self->default_photo_name){
    361363        $name = sprintf(
     
    363365            1+$i,
    364366            $self->default_name_prefix,
    365         )       
    366     }   
     367        )       
     368    }   
    367369    elsif('Prefix + create date chrono' eq $self->default_photo_name){
    368370        $name = sprintf(
     
    370372            $self->default_name_prefix,
    371373            $chrono,
    372         )       
    373     }   
     374        )       
     375    }   
    374376    elsif('Create date chrono + prefix' eq $self->default_photo_name){
    375377        $name = sprintf(
     
    377379            $chrono,
    378380            $self->default_name_prefix,
    379         )       
     381        )       
    380382    }
    381383
     
    388390
    389391     eval {
    390         printf("create gui thumbnail\n");
    391         # use the preview image to create a gui display thumbnail
    392392        if(!$self->CreateGUIThumbnail())
    393393        {
    394             print "CreateGUIThumbnail failed, use callback\n";
    395394            $self->ResizeCallback->(
    396395                $self->current_image->file,
     
    401400                $self->wx_quality,
    402401            );
    403                
     402           
    404403        }
    405404     };
     
    440439    splice @{$self->sums}, $index, 1 ;
    441440    $self->wx_thumb_imglist->Remove($index);
    442        
     441   
    443442}
    444443
     
    447446    my ( $self ) = @_;
    448447
    449 #    return 1 if( -e $self->current_image->wx_thumb_file );
    450448    my $rval = 0;
    451     print "CreateGUIThumbnail ", $self->current_image->wx_thumb_file, "\n";
    452449    my $image = new Image::Magick;
    453450
     
    471468
    472469
    473         # maximize size and keep aspect ratio
     470    # maximize size and keep aspect ratio
    474471    $status = $image->Thumbnail(
    475472        geometry=>sprintf("%s%s>", $size*$size, '@')
     
    493490        gravity=>'center',
    494491    );
    495        
     492   
    496493    $image->Set(
    497494        quality=>$self->wx_quality||90
     
    511508        );
    512509   
    513         $image->Rotate( degrees=>$1 ) if $self->auto_rotate;   
     510        $image->Rotate( degrees=>$1 ) if $self->auto_rotate;   
    514511    }
    515512   
     
    537534   
    538535    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
    545537
    546538    my $image = new Image::Magick;
     
    586578        );
    587579   
    588         $image->Rotate( degrees=>$1 ) if $self->auto_rotate;   
     580        $image->Rotate( degrees=>$1 ) if $self->auto_rotate;   
    589581    }
    590582
     
    671663    return {
    672664        map {
    673             $_ => $exif->{$_},
     665            $_ => $exif->{$_},
    674666        }
    675667        qw/
     
    698690            qw/
    699691                images
    700                 thumb_size
     692                thumb_size
    701693                preview_ratio
    702                 type
    703                 filter
    704                 blur
    705                 quality
    706                 wx_quality
    707                 th_quality
    708                 prefix
    709                 author
    710                 count
     694                type
     695                filter
     696                blur
     697                quality
     698                wx_quality
     699                th_quality
     700                prefix
     701                author
     702                count
    711703                resize_w
    712704                resize_h
    713                 hd_filter
    714                 hd_blur
    715                 hd_quality
     705                hd_filter
     706                hd_blur
     707                hd_quality
    716708                hd_w
    717709                hd_h
    718                                 hd_interlace
     710                hd_interlace
    719711                new_files
    720712                storable_file
    721                 wx_thumb_size
     713                wx_thumb_size
    722714                current_image
    723715                exif_metadata
     
    728720                progress_msg
    729721                default_photo_name
    730                 default_name_prefix
    731                 upload_high
    732                                 upload_hd
    733                 remove_uploaded_from_selection
    734                 auto_rotate
    735                 interlace
    736                 create_resized
    737                 use_exif_preview
    738                 image_sums
    739                 sums
     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
    740732                version
    741733                imagelist_version
     
    748740                watermark_x
    749741                watermark_color
    750                                 reupload_action_files
    751                                 reupload_action_properties
    752                                 reupload_action_properties_m
    753                                 display_mode
     742                reupload_action_files
     743                reupload_action_properties
     744                reupload_action_properties_m
     745                display_mode
    754746            /
    755747        ]
     
    760752    };
    761753    if($@){
    762         print $@, "\n"; 
     754        print $@, "\n";   
    763755    }
    764756}
     
    767759
    768760sub UploadSelection {
    769     my ( $self ) = @_; 
     761    my ( $self ) = @_;   
    770762
    771763    my $viewer_callback = $self->UploadImagesViewerCallback ;
     
    784776    $self->upload_begin_time(time);
    785777    $self->upload_selection_count(scalar @{$self->image_selection});
    786         # for re-upload management
     778    # for re-upload management
    787779    $self->upload_image_sums( [
    788                 map { $self->GetImage($_)->file_sum }
    789                     @{$self->image_selection}
    790             ]
    791         );
    792 
    793         # check if already exist on server
    794         my $uploaded = $self->pwg->IsAlreadyUploaded($self->upload_image_sums);
    795         my @already_uploaded = grep { $_ } values %$uploaded ;
    796         $self->ReuploadCallback->() if ( scalar @already_uploaded and !$self->reupload_not_ask );
    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   
    799791    foreach(@{$self->image_selection}) {
    800         # current image object         
    801         $self->current_image(
    802             $self->GetImage($_)
    803         );
     792    # current image object       
     793        $self->current_image(
     794            $self->GetImage($_)
     795        );
    804796        # prepare resized, high, thumbnail
    805                 # if not already uploaded
     797        # if not already uploaded
    806798        $self->_set_site_resized_file();
    807799        $self-> _set_site_high_file ();
    808800        # photo metadata
    809801        $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();       
    811803
    812804        # transfert resized, high, thumbnail to site
     
    817809            1+$self->count
    818810        );
     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/;
    819817    }
    820818
     
    848846    }
    849847
    850         my $decode = {
     848    my $decode = {
    851849        'No' => 0,
    852             'Yes, use HD resized of the original photo' => 'HD',
    853             'Yes, use a copy of the original photo' => 'ORIGINAL',
    854     }; 
     850        'Yes, use HD resized of the original photo' => 'HD',
     851        'Yes, use a copy of the original photo' => 'ORIGINAL',
     852    };   
    855853    #printf("upload HD %s\n", $self->upload_hd);
    856         $self->upload_high(
    857             $decode->{$self->upload_hd}
    858         );
     854    $self->upload_high(
     855        $decode->{$self->upload_hd}
     856    );
    859857    #printf("upload High %s\n", $self->upload_high);
    860        
     858   
    861859    # if upload high, rotate a copy of original file
    862860    if($self->upload_high){
     
    883881        );
    884882        # set current image thumbnail
    885         # update upload progress dialog
     883          # update upload progress dialog
    886884        #$self->progressbar_refresh->($value);
    887885    };
     
    970968            1+$self->upload_rejected_count
    971969        );
    972     }   
     970    }   
    973971       
    974972}
     
    10201018            sprintf(
    10211019                "%s_%sx%s.%s",
    1022                 $filename,
     1020#                $filename,
     1021                'resized',
    10231022                $self->resize_w,
    10241023                $self->resize_h,
     
    10271026        )
    10281027    );
    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);
    10301029}
    10311030
     
    10351034    eval {
    10361035        if(!$self->CreateResized()){
    1037             $self->__create_resized_fallback();
     1036            $self->_create_resized_fallback();
    10381037        };
    10391038
     
    10591058    my ( $self ) = @_;
    10601059    # use wx builtin rescale if IM fails
    1061     #printf("CreateResized failed %s. Use ResizeCallback\n", $@);
     1060    printf("CreateResized failed %s. Use ResizeCallback\n", $@);
    10621061    # use method provided by the caller
    10631062    # source, target, type, ratio, width, $height
     
    10661065        $self->current_image->site_resized_file,
    10671066        $self->type,
    1068         undef,
    10691067        $self->resize_w,
    10701068        $self->resize_h,
     
    10851083    my $bRotate;
    10861084    my $bAddWatermark;
    1087         my $bResize;
     1085    my $bResize;
    10881086    my $orientation = $self->current_image->exif_metadata->{Orientation};
    1089         my $degrees;
     1087    my $degrees;
    10901088   
    10911089    # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW
     
    10931091        $bModifyOriginal = 1;
    10941092        $bRotate = 1;
    1095                 $degrees = $1;
     1093        $degrees = $1;
    10961094    }
    10971095
     
    11001098        $bAddWatermark = 1;
    11011099    }
    1102        
    1103         # HD resize
    1104         if('HD' eq $self->upload_high){
     1100   
     1101    # HD resize
     1102    if('HD' eq $self->upload_high){
    11051103        $bModifyOriginal = 1;
    11061104        $bResize = 1;
    1107         }
     1105    }
    11081106
    11091107    if($bModifyOriginal){
     
    11321130        $status = $image->Set(interlace=>$self->interlace);
    11331131        warn "$status" if $status ;
    1134                
     1132       
    11351133        if($bRotate){
    1136             $image->Rotate( degrees=>$degrees );       
     1134            $image->Rotate( degrees=>$degrees );   
    11371135        }       
    11381136        $image->Write(
     
    11811179
    11821180# file name for original copy
     1181# we do not need the original file name
    11831182sub _set_site_high_file {
    11841183        my ( $self ) = @_;
     
    11951194                $self->site_resized_dir,
    11961195                sprintf(
    1197                     "%s_high.%s",
    1198                     $filename,
     1196                    "%s.%s",
     1197                     'high_file',
    11991198                    $self->type,
    12001199                )
     
    12451244    my ( $self ) = @_;
    12461245
    1247        
    1248         $self->pwg->reupload_action_files(
    1249             $self->reupload_action_files||1
    1250         );
    1251         $self->pwg->reupload_action_properties(
    1252             $self->reupload_action_properties||2
    1253         );
    1254 
    1255         $self->pwg->reupload_action_properties_m(
    1256             $self->reupload_action_properties_m||1
    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    );
    12581257   
    12591258    $self->pwg->upload_high(
     
    12891288    );
    12901289
    1291         $self->pwg->privacy_level(
    1292             $self->current_image->privacy_level
    1293         );
    1294        
     1290    $self->pwg->privacy_level(
     1291        $self->current_image->privacy_level
     1292    );
     1293   
    12951294    $self->current_image->site_categories(
    12961295        $self->categories
     
    13081307    );
    13091308
    1310        
     1309   
    13111310}
    13121311
     
    13351334        return 0 if $status;
    13361335   
    1337         $image->Rotate( degrees=>$1 ); 
     1336        $image->Rotate( degrees=>$1 );   
    13381337       
    13391338        # write resized file
     
    13461345        undef $image;
    13471346   
    1348     }   
     1347    }   
    13491348    return 1;
    13501349}
  • extensions/pLoader/trunk/src/Uploader/PWG/WebServices.pm

    r4610 r4747  
    6464           image_id
    6565           typecode
    66                    reupload_action_files
    67                    reupload_action_properties
    68                    reupload_action_properties_m
    69                    single_value_mode
    70                    multiple_value_mode
    71                    privacy_level
     66           reupload_action_files
     67           reupload_action_properties
     68           reupload_action_properties_m
     69           single_value_mode
     70           multiple_value_mode
     71           privacy_level
    7272      /
    7373);
     
    8383             file => 'file',
    8484             thumbnail => 'thumb',
    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        
     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   
    103103    $self->uagent(
    104104        LWP::UserAgent->new(
     
    107107    );
    108108   
    109     $self->uagent->cookie_jar({});     
     109    $self->uagent->cookie_jar({});   
    110110
    111111    $self->urlbase(
     
    174174            );
    175175        };
    176                 if($@){
     176        if($@){
    177177            # when server response has warnings, the content response is not a valid json string
    178                     # find the json response
     178            # find the json response
    179179            $self->uagent_response->content =~ /(\{.+\})/;
    180                     #printf("json response %s\n", $1);
     180            #printf("json response %s\n", $1);
    181181            eval {
    182182                $hresult = from_json(
     
    184184                );
    185185            };
    186         }               
     186        }       
    187187    }
    188188    else{
    189         $hresult = {
     189        $hresult = {
    190190            'message' => $self->uagent_response->message,
    191191            'stat'    => 'fail',
    192192        };
    193193    }
    194        
    195         $hresult;
     194   
     195    $hresult;
    196196}
    197197
     
    203203            $self->uagent->get(
    204204                $query
    205                     )
     205            )
    206206        );
    207207    };
     
    211211            $query,
    212212            $@,
    213         );     
     213        );   
    214214    }
    215215}
     
    226226            )
    227227        );
    228         };
     228    };
    229229
    230230    if($@){
     
    232232            $form->{method},
    233233            $@,
    234         );     
     234        );   
    235235    }
    236        
    237         return ( $result->is_success, $result->status_line );
     236   
     237    return ( $result->is_success, $result->status_line );
    238238}
    239239sub GetCategories {
     
    242242 
    243243    $self->_execute_get(
    244             $self->qry_list_categories
    245         );
     244        $self->qry_list_categories
     245    );
    246246    $self->_json_response_content->{result}{categories};
    247247}
     
    251251
    252252    $self->_execute_get(
    253         $self->qry_list_tags   
    254         );
     253        $self->qry_list_tags   
     254    );
    255255    $self->_json_response_content->{result}{tags};
    256256}
     
    295295            } @types;
    296296         
    297         
     297          
    298298            $form = {
    299299                method            => 'pwg.images.add',
     
    311311
    312312           $form->{high_sum} = $self->sum->{high} if $self->upload_high;
    313                    
     313           
    314314           $progress->{yield}->();
    315315           ( $status, $status_line ) = $self->_execute_post($form);
    316                 }
     316        }
    317317        # re-upload
    318318        else{
     
    323323                my $files = $self->_check_files();
    324324                if(defined($files)){
    325                     $self->_add_files($files, $progress);       
     325                    $self->_add_files($files, $progress);   
    326326                }
    327327            }
     
    330330                    method        => 'pwg.images.setInfo',
    331331                    image_id      => $self->image_id,
    332                     };
     332            };
    333333            # 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){     
    336336                $form->{name}          = $self->site_image_name;
    337337                $form->{author}        = $self->site_author;
    338338                $form->{comment}       = $self->site_comment;
    339339                $form->{date_creation} = $self->site_img_date_creation;
    340                                 $form->{single_value_mode}  = $self->single_value_mode->{$self->reupload_action_properties};
     340                $form->{single_value_mode}  = $self->single_value_mode->{$self->reupload_action_properties};
    341341                $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){     
    345345                $form->{tag_ids} = $self->site_tags if $self->site_tags;
    346346                $form->{categories} = $self->categories;
    347                                 $form->{multiple_value_mode} = $self->multiple_value_mode->{$self->reupload_action_properties_m};
     347                $form->{multiple_value_mode} = $self->multiple_value_mode->{$self->reupload_action_properties_m};
    348348            };
    349349            $progress->{yield}->();
    350350            ( $status, $status_line ) = $self->_execute_post($form);
    351351
    352                 }
     352        }
    353353
    354354        delete $form->{tag_ids} unless defined $self->site_tags;
     
    357357        $progress->{yield}->();
    358358        # for first upload
     359        # make sure the image is uploaded by querying for its existence
    359360        if($doubleCheck){
    360                     $self->image_id(
    361                             $self->_exists($progress->{original_sum})
    362                         );
     361            $self->image_id(
     362                $self->_exists($progress->{original_sum})
     363            );
    363364            $content->{stat} = !defined $self->image_id  ? 'fail' : 'ok';
    364365            if(defined $self->image_id and defined $self->privacy_level){
    365                     ( $status, $status_line, $content ) = $self->_set_privacy_level;
    366                 }
    367         }
    368 
    369                 last UPLOAD;
     366                ( $status, $status_line, $content ) = $self->_set_privacy_level;
     367            }
     368        }
     369
     370        last UPLOAD;
    370371    }# UPLOAD
    371372   
     
    375376sub _set_privacy_level {
    376377    my ( $self ) = @_;
    377                
     378       
    378379    my $form = {
    379380        method        => 'pwg.images.setPrivacyLevel',
     
    381382        level         => $self->privacy_level ? 2**($self->privacy_level - 1) : 0,
    382383    };
    383         print Dumper $form;
    384         my ( $status, $status_line ) = $self->_execute_post($form);
     384    print Dumper $form;
     385    my ( $status, $status_line ) = $self->_execute_post($form);
    385386    my $hresult = $self->_json_response_content;
    386387
     
    405406    );
    406407
    407             high => $self->_checksum(
    408                         $self->site_high_file,
    409                         $progress
    410                     ),
    411 
    412408    $self->sum->{high} = $self->_checksum(
    413409                        $self->site_high_file,
     
    457453        $self->typecode->{$_};
    458454    } grep { 'equals' ne $files->{$_} } keys %$files ;
    459        
     455       
    460456}
    461457
     
    472468        image_id => $self->image_id,
    473469        type     => $type_code,
    474         sum      => $self->sum->{$type_code},           
    475     }; 
     470        sum      => $self->sum->{$type_code},       
     471    };   
    476472
    477473    $self->_execute_post($form);   
     
    485481sub IsAlreadyUploaded {
    486482    my ( $self, $md5_sums ) = @_;
    487        
    488         # md5_sums is an array ref
    489         $self->_execute_post({
     483   
     484    # md5_sums is an array ref
     485    $self->_execute_post({
    490486        method      => 'pwg.images.exist',
    491487        md5sum_list => join(',', @$md5_sums)
    492             }
    493         );
    494 
    495         my $sums = $self->_json_response_content->{result};
     488        }
     489    );
     490
     491    my $sums = $self->_json_response_content->{result};
    496492
    497493    $sums;
     
    509505    my $hresult = $self->_json_response_content;
    510506
    511         $hresult->{result} = {} if 'HASH' ne ref $hresult->{result};
     507    $hresult->{result} = {} if 'HASH' ne ref $hresult->{result};
    512508    my $id = 'ok' eq $hresult->{stat} ? $hresult->{result}{$md5_sum} : undef ;
    513509
     
    529525        )
    530526    );
     527
    531528    eval {
    532529        $file_sum = file_md5_hex(
     
    581578       
    582579    };
    583        
     580   
    584581    return ( $self->_execute_post($form), $self->_json_response_content );
    585582}
Note: See TracChangeset for help on using the changeset viewer.