Changeset 3177


Ignore:
Timestamp:
Mar 7, 2009, 8:22:06 PM (15 years ago)
Author:
ronosman
Message:

Features 914, 920, 921, 924 added ( sorry plg, it's a global commit ). Add an option to upload an already resized image. In that case, pLoader does not create any resized image and uploads original as a resized. Add properties to define custom preview ( option to not use exif preview and create a preview based on a preview ratio ).

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

Legend:

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

    r2728 r3177  
    3737        site_categories
    3838        site_tags
     39        preview_w
     40        preview_h
    3941    /
    4042);
  • extras/pLoader/trunk/src/Uploader/ImageList.pm

    r3163 r3177  
    7272                pwg
    7373                upload_high
     74                wx_quality
     75                th_quality
     76                auto_rotate
     77                interlace
     78                create_resized
     79                use_exif_preview
    7480     /
    7581);
     
    101107}
    102108
    103 # Rotate exif preview if needed
    104 sub _rotate_image {
    105     my ( $self, $file ) = @_;   
    106 
    107 }
    108109
    109110sub _set_exif_tag {
     
    205206        $self->_set_current_image_filepaths();
    206207
    207         my $create_gui_preview;       
    208         # an exif preview is available. we try to use it
    209         if(defined $info->{PreviewImage} ){
    210             printf("use preview\n");
    211             $self->_write_preview_image( $info->{PreviewImage} );
    212             my $image = new Image::Magick;
    213             eval {
    214                 $create_gui_preview = $image->ReadImage(
    215                     $self->current_image->preview_file
    216                 );
    217             };
    218             unlink $self->current_image->preview_file if $create_gui_preview;
    219         }else {
     208        my $create_gui_preview;
     209        if($self->use_exif_preview){       
     210            # an exif preview is available. we try to use it
     211            if(defined $info->{PreviewImage} ){
     212                printf("use preview\n");
     213                $self->_write_preview_image( $info->{PreviewImage} );
     214                my $image = new Image::Magick;
     215                eval {
     216                        $create_gui_preview = $image->ReadImage(
     217                        $self->current_image->preview_file
     218                    );
     219                };
     220                unlink $self->current_image->preview_file if $create_gui_preview;
     221            }
     222            else {
     223                $create_gui_preview = 1;
     224            }
     225        }
     226        else {
    220227            $create_gui_preview = 1;
    221228        }
    222         print $create_gui_preview, "\n";
     229        print "create gui preview", $create_gui_preview, "\n";
    223230        # have to create a preview file
    224231        if($create_gui_preview) {
     
    242249        $self->RotateImage(
    243250            $self->current_image->preview_file,
    244         );
     251        ) if $self->auto_rotate;
    245252
    246253        $self->_set_exif_tag(
     
    248255            'Orientation',
    249256            'Horizontal (normal)',
    250         );
     257        ) if $self->auto_rotate;
    251258
    252259
     
    357364    return $rval if $status;
    358365
     366    $self->current_image->preview_w(
     367        $image->Get('width')
     368    );
     369    $self->current_image->preview_h(
     370        $image->Get('height')
     371    );
     372
     373
    359374    $status = $image->Thumbnail(
    360375        geometry=>sprintf("%s%s>", $size*$size, '@')
     
    374389    );
    375390
    376     $image->Set(quality=>100);
     391    $image->Set(
     392        quality=>$self->wx_quality
     393    );
    377394
    378395    $status = $image->Strip();
     
    398415sub CreateGUIPreview {
    399416    my ( $self ) = @_;
    400 
     417    printf("CreateGUIPreview %s\n", $self->current_image->preview_file );
    401418    return 1 if( -e $self->current_image->preview_file );
    402419   
     
    410427    my $status = $image->Read(
    411428        sprintf(
    412             "'%s'",
     429            "%s",
    413430            $self->current_image->file,
    414431        )
     
    435452
    436453
    437     $image->Set(quality=>$self->quality);
     454    $image->Set(quality=>$self->wx_quality);
    438455
    439456
     
    460477    return $rval if( -e $self->current_image->site_resized_file );
    461478
    462 printf(
    463     "Create resized %s\n",
    464     $self->current_image->file,
    465 );     
     479    printf(
     480        "Create resized %s\n",
     481        $self->current_image->file,
     482    );     
    466483
    467484    my $image = new Image::Magick;
     
    513530    warn "$status" if $status ;
    514531
    515     $status = $image->Set(interlace=>'Line');
     532    $status = $image->Set(interlace=>$self->interlace);
    516533    warn "$status" if $status ;
    517534
     
    561578    warn "$status" if $status ;
    562579
    563     $status = $image->Set(quality=>$self->quality);
     580    $status = $image->Set(quality=>$self->th_quality);
    564581    warn "$status" if $status ;
    565582
     
    624641                blur
    625642                quality
     643                wx_quality
     644                th_quality
    626645                prefix
    627646                author
     
    643662                default_name_prefix
    644663                upload_high
     664                auto_rotate
     665                interlace
     666                create_resized
     667                use_exif_preview
    645668            /
    646669        ]
     
    722745        croak "Upload cancelled." if $@ ;
    723746
    724         eval {
    725             if(!$self->CreateResized()){
    726                 printf("CreateResized failed %s. Use ResizeCallback\n", $@);
    727                 # use method provided by the caller
    728                 # source, target, type, ratio, width, $height
    729                 $self->ResizeCallback->(
    730                     $self->current_image->file,
    731                     $self->current_image->site_resized_file,
    732                     $self->type,
    733                     undef,
    734                     $self->resize_w,
    735                     $self->resize_h,
    736                     $self->quality,
    737                 );
     747        if( $self->create_resized ){
     748            eval {
     749                if(!$self->CreateResized()){
     750                    printf("CreateResized failed %s. Use ResizeCallback\n", $@);
     751                    # use method provided by the caller
     752                    # source, target, type, ratio, width, $height
     753                    $self->ResizeCallback->(
     754                        $self->current_image->file,
     755                        $self->current_image->site_resized_file,
     756                        $self->type,
     757                        undef,
     758                        $self->resize_w,
     759                        $self->resize_h,
     760                        $self->quality,
     761                    );
    738762               
    739                 $self->RotateImage(
    740                     $self->current_image->site_resized_file,
    741                 );
    742             }
    743         };
    744 
    745         $self->_set_exif_tag(
    746             $self->current_image->site_resized_file,
    747             'Orientation',
    748             'Horizontal (normal)',
    749         );
     763                    $self->RotateImage(
     764                        $self->current_image->site_resized_file,
     765                    ) if $self->auto_rotate;
     766                }
     767            };
     768            $self->_set_exif_tag(
     769                $self->current_image->site_resized_file,
     770                'Orientation',
     771                'Horizontal (normal)',
     772            ) if $self->auto_rotate;
     773        }
     774        # the original is at the right size, no need to create a resize
     775        else {
     776            $self->current_image->site_resized_file(
     777                $self->current_image->file,
     778            );
     779        }
     780
    750781
    751782
     
    754785            $self->CreateHigh();
    755786        }
    756 
    757 
    758 
    759787
    760788        $msg = sprintf(
     
    848876   
    849877    # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW
    850     if( $orientation =~ m/Rotate (\d+)/ ){
     878    if( $self->auto_rotate and $orientation =~ m/Rotate (\d+)/ ){
    851879
    852880        my ( $vol, $dir, $file ) = File::Spec->splitpath(
     
    892920        );
    893921
    894 
    895922        # Now all images that need to be rotated are done. Update exif
    896923        $self->current_image->exif_metadata->{Orientation} = 'Horizontal (normal)';
Note: See TracChangeset for help on using the changeset viewer.