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

Feature 1400 added : remove resized image file cache.

File:
1 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}
Note: See TracChangeset for help on using the changeset viewer.