Changeset 2728


Ignore:
Timestamp:
Oct 12, 2008, 9:16:39 PM (16 years ago)
Author:
ronosman
Message:

Feature added : auto rotate image using exif metadata
Feature added : upload in high resolution
Improved user feedback in upload progress dialog

Location:
extras/pLoader/trunk/src/Uploader
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extras/pLoader/trunk/src/Uploader/GUI/wxExportProgressDlg.pm

    r2597 r2728  
    2020package Uploader::GUI::wxExportProgressDlg;
    2121use strict;
     22use Carp;
    2223use Wx qw/
    2324             wxDefaultSize
     
    4041           processing
    4142           txtprocessing
     43           cancelled
    4244      /
    4345);
     
    7577# Update progress information
    7678sub LogProgress {
    77     my ( $self, $text, $value ) = @_;
    78    
    79    
     79    my ( $self ) = @_;
     80
     81printf("$self cancelled %s \n", $self->cancelled);
     82    die if $self->cancelled;   
    8083    $self->txtprocessing->SetLabel(
    8184        $text || $self->processing
     
    8487        $value || $self->progress
    8588    );
     89
    8690}
    8791
    88 
     92# Close the dialog. cancel export
    8993sub OnExportOK {
    9094    my ( $self, $event ) = @_;
    9195   
     96    $self->cancelled(1);
    9297    $self->Destroy;
    9398 
  • extras/pLoader/trunk/src/Uploader/GUI/wxFrameAUI.pm

    r2698 r2728  
    151151
    152152
    153     # callback for GUI refresh : progress dialog display current uploaded image
    154     $self->imagelist->UploadImagesProgressCallback(
    155         sub { $self->UploadImagesProgress(@_) }
    156     );
    157    
    158     $self->imagelist->UploadDisplayEndInfoCallback(
     153    # callback for GUI refresh : progress dialog display current uploaded image
     154    $self->imagelist->progress_thumbnail_refresh(
     155        sub { $self->UploadProgressThumbnailRefresh(@_) }
     156    );
     157
     158    $self->imagelist->progress_msg_refresh(
     159        sub { $self->UploadProgressMessageRefresh(@_) }
     160    );
     161
     162
     163    $self->imagelist->progressbar_refresh(
     164        sub { $self->UploadProgressBarRefresh(@_) }
     165    );
     166   
     167    $self->imagelist->progress_endinfo_refresh(
    159168        sub { $self->UploadDisplayEndInfo(@_) }
    160169    );
     
    786795}
    787796
    788 # display uploaded image in progress dlg
    789 sub UploadImagesProgress {
     797sub UploadProgressMessageRefresh {
     798    my ( $self, $msg ) = @_;   
     799
     800    $self->upload_progressdlg->processing(
     801        $msg   
     802    ); 
     803
     804    Wx::Yield();
     805}
     806
     807sub UploadProgressThumbnailRefresh {
    790808    my ( $self ) = @_; 
    791    
     809
    792810    my $imagelist = $self->imagelist ;
    793811
    794     my ( $vol, $dir, $file ) = File::Spec->splitpath($imagelist->current_image->file);
    795 
    796     $self->upload_progressdlg->processing(
    797         sprintf(
    798             $imagelist->progress_msg,
    799             $imagelist->current_image->site_name,
    800             $file,
     812 
     813    $self->upload_progressdlg->image->SetBitmap(wxNullBitmap);
     814    $self->upload_progressdlg->image->SetBitmap(
     815        Wx::Bitmap->new(
     816            $self->imagelist->current_image->wx_thumb_file,
     817            $self->GetWxBitmapType($self->imagelist->type),
    801818        )
    802819    );
     820
     821    Wx::Yield();
     822}
     823
     824sub UploadProgressBarRefresh {
     825    my ( $self, $ratio ) = @_; 
     826
    803827    eval {
    804         $self->upload_progressdlg->image->SetBitmap(wxNullBitmap);
    805         $self->upload_progressdlg->image->SetBitmap(
    806             Wx::Bitmap->new(
    807                 $self->imagelist->current_image->wx_thumb_file,
    808                 $self->GetWxBitmapType($self->imagelist->type),
    809             )
    810         );
    811828        $self->upload_progressdlg->progress(
    812             $imagelist->count * ( 100/scalar @{$imagelist->image_selection} )
     829            $ratio*$self->imagelist->count * ( 100/scalar @{$self->imagelist->image_selection} )
    813830        );
    814831        $self->upload_progressdlg->LogProgress();
    815832    };
    816     if($@){
    817         croak "Upload cancelled.\n";
    818     }
    819    
     833    croak "Upload cancelled" if $@;
     834
    820835    Wx::Yield();
    821 
    822 }
    823 
     836}
    824837
    825838sub SetNewFilesDisplayEndInfo {
     
    830843
    831844sub UploadDisplayEndInfo {
    832     my ( $self ) = @_; 
     845    my ( $self, $msg ) = @_;   
    833846   
    834847    my $imagelist = $self->imagelist ;
    835848   
    836     $self->upload_progressdlg->DisplayEndInfo;
     849    $self->upload_progressdlg->DisplayEndInfo($msg);
    837850}
    838851
  • extras/pLoader/trunk/src/Uploader/GUI/wxImageProcessingProgressDlg.pm

    r2597 r2728  
    4141           txtprocessing
    4242           image
     43           cancelled
    4344      /
    4445);
    45 
     46use Carp;
    4647
    4748sub new {
     
    6566    };
    6667
     68    $self->btok->SetLabel(
     69        $params->{bt_label}||'Cancel'
     70    );
     71
    6772    if($@){
    6873        Wx::LogMessage("Error during dialogbox initialization");
     
    7580    my ( $self ) = @_;
    7681   
    77     EVT_BUTTON( $self, $main::ID_PROGRESS_OK, \&OnExportOK );
     82    EVT_BUTTON( $self, $main::ID_PROGRESS_OK, \&OnOK );
    7883   
    7984       
     
    8287# Update progress information
    8388sub LogProgress {
    84     my ( $self, $text, $value ) = @_;
     89    my ( $self ) = @_;
    8590   
     91    croak "Cancelled by user\n" if $self->cancelled;   
    8692   
    8793    $self->txtprocessing->SetLabel(
    88         $text || $self->processing
     94        $self->processing
    8995    );
    9096    $self->gauge->SetValue(
    91         $value || $self->progress
     97        $self->progress
    9298    );
    9399}
    94100
     101sub DisplayEndInfo {
     102    my ( $self, $msg ) = @_;
    95103
    96 sub OnExportOK {
     104    $self->txtprocessing->SetLabel(
     105        $msg
     106    );
     107    $self->image->Show(0);
     108    $self->gauge->Show(0);
     109
     110    $self->btok->SetLabel(
     111        'Close'
     112    );
     113       
     114}
     115
     116sub OnOK {
    97117    my ( $self, $event ) = @_;
    98118   
     119    $self->cancelled(1);
    99120    $self->Destroy;
    100121 
  • extras/pLoader/trunk/src/Uploader/Image.pm

    r2597 r2728  
    2727        wx_thumb_file
    2828        preview_file
     29        site_high_file
    2930        site_name
    3031        site_resized_file
  • extras/pLoader/trunk/src/Uploader/ImageList.pm

    r2696 r2728  
    6464                SetNewFilesDisplayEndInfoCallback
    6565                UploadImagesViewerCallback
    66                 UploadImagesProgressCallback
    67                 UploadDisplayEndInfoCallback
     66                progress_thumbnail_refresh
     67                progress_msg_refresh
     68                progressbar_refresh
     69                progress_endinfo_refresh
    6870                ResizeCallback
    6971                upload_rejects
     
    615617    my ( $self ) = @_; 
    616618
    617     my $progress_msg;
    618     my $progress_callback = $self->UploadImagesProgressCallback;
    619619    my $viewer_callback = $self->UploadImagesViewerCallback ;
    620620
     
    624624    );
    625625
    626     my $count = 0;
    627 
     626    my $count = 1;
     627    my $msg;
    628628    $self->count(
    629629        $count
    630630    );
     631    my $uploaded = 0;
     632    my $rejected = 0;
     633    my $time_begin = time;
    631634    map {
    632635        # current image object         
     
    638641            $self->current_image->file
    639642        );
     643       
     644        my $site_name = $self->current_image->site_name;
    640645   
    641646        my ( $filename, $ext ) = split /\./, $file ;
    642647
    643         # is defined lately to make sure we have the last global properties ( resize_w, resize_h )
     648        # lately defined to make sure we have the last global properties ( resize_w, resize_h )
    644649        $self->current_image->site_resized_file(
    645650            File::Spec->catfile(
     
    654659            )
    655660        );
    656        
    657 
    658         $self->progress_msg(
    659             "Preparing resized image for %s - %s"
    660         );
    661    
    662         # update upload progress dialog
     661       
     662        $msg = sprintf(
     663            "Preparing resized image for %s - %s",
     664            $site_name,
     665            $file,
     666        );
     667
    663668        eval {
    664             $progress_callback->();
     669            # set current image thumbnail
     670            $self->progress_thumbnail_refresh->();
     671
     672            $self->progress_msg_refresh->($msg);
     673   
     674            # update upload progress dialog
     675            $self->progressbar_refresh->(0.25);
    665676        };
    666         # user cancelled
    667         if($@){
    668             croak "Upload cancelled.";
    669         }
     677        # user cancelled : dialog box is destroyed
     678        croak "Upload cancelled." if $@ ;
     679
    670680        eval {
    671681            if(!$self->CreateResized()){
     
    695705
    696706
    697         if($@){
    698             $progress_msg = "An error has occured %s - %s\n$@";
     707        # if upload high, rotate a copy of original file
     708        if($self->upload_high){
     709            $self->CreateHigh();
    699710        }
    700         else{
    701             $progress_msg = "Preparing thumbnail for %s - %s";
    702         }
    703 
    704         $self->progress_msg(
    705              $progress_msg
    706         );
    707         # update upload progress dialog
    708         $progress_callback->();
     711
     712
     713
     714
     715        $msg = sprintf(
     716            "Preparing thumbnail for %s - %s",
     717            $site_name,
     718            $file,
     719        );
     720
     721        eval {
     722            $self->progress_msg_refresh->($msg);
     723        };
     724        croak "Upload cancelled." if $@ ;
    709725
    710726        eval {
    711727            $self->CreateThumbnail();
    712728        };
     729
    713730        if($@){
    714             $self->progress_msg(
    715                 "An error has occured  %s - %s\n$@"
     731            $msg = sprintf(
     732                "An error has occured %s - %s\n$@",
     733                $site_name,
     734                $file
    716735            );
    717736        }
    718737        else{
    719             $self->progress_msg(
    720                 "Uploading %s - %s"
     738            $msg = sprintf(
     739                "Uploading %s - %s",
     740                $site_name,
     741                $file
    721742            );
    722743        }
    723         # update upload progress dialog
    724         $progress_callback->() ;
     744        eval {
     745            $self->progress_msg_refresh->($msg);
     746            $self->progressbar_refresh->(0.50);
     747        };
     748        croak "Upload cancelled." if $@ ;
    725749
    726750        # photo metadata
     
    729753
    730754        if ( $status ){
    731             $self->progress_msg(
    732                 "%s : %s upload succcessful."
     755            $msg = sprintf(
     756                "%s : %s upload succcessful.",
     757                $site_name,
     758                $file
    733759            );
     760            $uploaded++;
    734761        } else {
    735             $self->progress_msg(
    736                 "An error has occured.\n%s : %s upload is cancelled.\n$status_msg"
     762            $msg = sprintf(
     763                "An error has occured.\n%s : %s upload is cancelled.\n$status_msg",
     764                $site_name,
     765                $file
    737766            );
    738             push @{$self->upload_rejects}, $self->current_image ;
     767            $rejected++;
    739768        }       
    740769       
     
    744773        );
    745774        # update upload progress dialog
    746         $progress_callback->() ;
     775        eval {
     776            $self->progress_msg_refresh->($msg);
     777            $self->progressbar_refresh->(1);
     778        };
     779        croak "Upload cancelled." if $@ ;
    747780       
    748781    }
    749782    @{$self->image_selection} if defined
    750783        $self->image_selection;
    751        
    752     $self->UploadDisplayEndInfoCallback->();
     784
     785    my $time_end = time;
     786    my $duration = $time_begin - $time_end;
     787    $msg = sprintf(
     788        "%s images processed\n\n%s images uploaded\n\n%s images in errors and not uploaded\n\nDuration : %s seconds",
     789        $self->count - 1,
     790        $uploaded,
     791        $rejected,
     792        $duration,
     793    );
     794    $self->progress_endinfo_refresh->($msg);
     795}
     796
     797# if we need to rotate
     798sub CreateHigh {
     799    my ( $self ) = @_;
     800
     801    my $orientation = $self->current_image->exif_metadata->{Orientation};
     802   
     803    # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW
     804    if( $orientation =~ m/Rotate (\d+)/ ){
     805
     806        my ( $vol, $dir, $file ) = File::Spec->splitpath(
     807            $self->current_image->file
     808        );
     809   
     810        my ( $filename, $ext ) = split /\./, $file ;
     811   
     812        # high_file is a copy of original
     813        $self->current_image->site_high_file(
     814            File::Spec->catfile(
     815                $self->site_resized_dir,
     816                sprintf(
     817                    "%s_high.%s",
     818                    $filename,
     819                    $self->type,
     820                )
     821            )
     822        );
     823
     824        my $image = Image::Magick->new();
     825        # we read original
     826        my $status = $image->Read(
     827            $self->current_image->file
     828        );
     829        warn "$status ", $self->current_image->file, "\n" if $status ;
     830        return 0 if $status;
     831
     832        $image->Rotate( degrees=>$1 ); 
     833       
     834        $image->Write(
     835            filename=>$self->current_image->site_high_file
     836        );
     837        warn "$status ", $self->current_image->site_high_file, "\n" if $status ;
     838        return 0 if $status;
     839       
     840        undef $image;
     841
     842        $self->_set_exif_tag(
     843            $self->current_image->site_high_file,
     844            'Orientation',
     845            'Horizontal (normal)',
     846        );
     847
     848
     849        # Now all images that need to be rotated are done. Update exif
     850        $self->current_image->exif_metadata->{Orientation} = 'Horizontal (normal)';
     851    }
     852    else{
     853        # high file is the original file
     854        $self->current_image->site_high_file(
     855            $self->current_image->file
     856        );
     857    }
     858
     859    return 1;
    753860}
    754861
     
    810917    my ( $self, $file ) = @_;
    811918   
     919    # exif from original image
    812920    my $orientation = $self->current_image->exif_metadata->{Orientation};
    813921   
     
    820928
    821929        my $image = Image::Magick->new();
    822    
     930       
     931        # read resized file
    823932        my $status = $image->Read(
    824933            $file
     
    829938        $image->Rotate( degrees=>$1 ); 
    830939       
     940        # write resizd file
    831941        $image->Write(
    832942            filename=>$file
  • extras/pLoader/trunk/src/Uploader/PWG/WebServices.pm

    r2696 r2728  
    160160   
    161161
    162     printf(
    163         "UploadImage %s\n",
    164         $self->site_resized_file
    165     );
    166162
    167163    my $file_content = encode_base64(
     
    205201
    206202    if($self->upload_high){
    207         $form->{high_content} = encode_base_64(
     203        $form->{high_content} = encode_base64(
    208204                                     read_file(
    209205                                         $self->site_high_file,
     
    211207                                     )
    212208                                 );
     209
    213210        $form->{high_sum}     = file_md5_hex(
    214211                                     $self->site_high_file
Note: See TracChangeset for help on using the changeset viewer.