Changeset 4088


Ignore:
Timestamp:
Oct 22, 2009, 8:26:46 PM (15 years ago)
Author:
ronosman
Message:

Feature 1136 added : Add a watermark on resized and/or high definition photo. First version is text only.

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

Legend:

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

    r4086 r4088  
    336336          preview_settings_panel
    337337          advanced_settings_panel
     338          watermark_settings_panel
    338339          piwigo_properties
    339340          exif_properties
     
    343344          preview_settings
    344345          advanced_settings
     346          watermark_settings
    345347          toolbar
    346348          branding
     
    720722    );
    721723
     724    $self->watermark_settings(
     725        [
     726            {
     727              label  => gettext("Activate watermark :"),
     728              type   => 'Bool',
     729              value  => sub { $self->imagelist->watermark_activate(@_) },
     730            },
     731            {
     732              label => gettext("Activate watermark on high definition :"),
     733              type  => 'Bool',
     734              value => sub { $self->imagelist->watermark_activate_pwg_high(@_) },
     735            },
     736            {
     737              label  => gettext("Text :"),
     738              value  => sub { $self->imagelist->watermark_text(@_) },
     739            },
     740            {
     741                label     => gettext("Text size :"),
     742                type      => 'Number',
     743                value   => sub { $self->imagelist->watermark_text_size(@_) },
     744            },
     745            {
     746                label     => gettext("Color :"),
     747                type      => 'Choice',
     748                value   => sub { $self->imagelist->watermark_color(@_) },
     749                choice  => [
     750                                  gettext("White"),
     751                                  gettext("Black"),
     752                           ],
     753            },           
     754            {
     755                label     => gettext("Position :"),
     756                type      => 'Choice',
     757                value   => sub { $self->imagelist->watermark_position(@_) },
     758                choice  => [
     759                                  gettext("Top"),
     760                                  gettext("Top left"),
     761                                  gettext("Top right"),
     762                                  gettext("Bottom"),
     763                                  gettext("Bottom left"),
     764                                  gettext("Bottom right"),
     765                                  gettext("Center"),
     766                                  gettext("Left"),
     767                                  gettext("Right"),
     768                           ],
     769            },
     770            {
     771                label     => gettext("Top margin :"),
     772                type      => 'Number',
     773                value   => sub { $self->imagelist->watermark_y(@_) },
     774            },
     775            {
     776                label     => gettext("Left margin :"),
     777                type      => 'Number',
     778                value   => sub { $self->imagelist->watermark_x(@_) },
     779            },           
     780        ]
     781    );
     782
    722783    $self->image_tags(
    723784        sub { eval { $self->imagelist->current_image->site_tags(@_) } }
     
    764825        $self->preview_settings_panel,
    765826        $self->advanced_settings_panel,
     827        $self->watermark_settings_panel,
    766828    );
    767829   
     
    841903    );   
    842904
     905    $self->watermark_settings_panel->properties(
     906        $self->watermark_settings,
     907    ); 
    843908       
    844909}
     
    924989        )   
    925990    );   
     991
     992    $self->watermark_settings_panel(
     993        Uploader::GUI::wxPropertyGridPanel->new(
     994            {
     995                parentwnd   => $self,
     996                properties  => $self->watermark_settings,
     997                frame_callbacks => [],
     998            }
     999        )
     1000    );
    9261001
    9271002    $self->image_prop_tags(
     
    12441319            gettext("Advanced"),
    12451320        ],
     1321        [
     1322            $self->watermark_settings_panel,
     1323            gettext("Watermark"),
     1324        ]   
    12461325    ];
    12471326   
  • extensions/pLoader/trunk/src/Uploader/ImageList.pm

    r4086 r4088  
    3232use Wx::Locale qw/:default/;
    3333use Wx;
    34 
     34use Path::Class::Unicode;
    3535# this class implements a collection of image files with associated data
    3636$|=1;
     
    9393                imagelist_version
    9494                uploaded_images
     95                watermark_activate
     96                watermark_activate_pwg_high
     97                watermark_text
     98                watermark_text_size
     99                watermark_position
     100                watermark_y
     101                watermark_x
     102                watermark_color
     103                gravity
     104                rgbcolor
    95105     /
    96106);
     
    101111   
    102112    $self->uploaded_images([]);
     113    $self->gravity(
     114        {
     115            gettext("Top") => 'North',
     116            gettext("Left") => 'West',
     117            gettext("Right") => 'East',
     118            gettext("Bottom") => 'South',
     119            gettext("Top left") => 'NorthWest',
     120            gettext("Top right") => 'NorthEast',
     121            gettext("Bottom left") => 'SouthWest',
     122            gettext("Bottom right") => 'SouthEast',
     123            gettext("Center") => 'Center',
     124       }   
     125    );   
     126
     127    $self->rgbcolor(
     128        {
     129            gettext("White") => '#FFFFFF',
     130            gettext("Black") => '#000000',
     131        }   
     132    );
    103133   
    104134}
     
    642672        $resize_h = $resize_w_;
    643673    }
    644    
     674    printf("resize with blur value %s\n", $self->blur);
    645675    $status = $image->Resize(
    646676        geometry => sprintf("%sx%s>", $resize_w, $resize_h),
     
    667697    }
    668698
     699    printf("resize with quality value %s\n", $self->quality);
    669700    $status = $image->Set(quality=>$self->quality);
    670701    warn "$status" if $status ;
     
    811842                version
    812843                imagelist_version
     844                watermark_activate
     845                watermark_activate_pwg_high
     846                watermark_text
     847                watermark_text_size
     848                watermark_position
     849                watermark_y
     850                watermark_x
     851                watermark_color
    813852            /
    814853        ]
     
    916955                'Horizontal (normal)',
    917956            ) if $self->auto_rotate;
     957
     958            $self->CreateWatermark(
     959               $self->watermark_text,
     960               $self->watermark_text_size,
     961               $self->watermark_position,
     962               $self->watermark_x,
     963               $self->watermark_y,
     964               $self->watermark_color,
     965               $self->current_image->site_resized_file
     966           ) if $self->watermark_activate;
    918967        }
    919968        # the original is at the right size, no need to create a resize
     
    10461095    my ( $self ) = @_;
    10471096
     1097    my $bModifyOriginal;
     1098    my $bRotate;
     1099    my $bAddWatermark;
    10481100    my $orientation = $self->current_image->exif_metadata->{Orientation};
    10491101   
    10501102    # Valid for Rotate 180, Rotate 90 CW, Rotate 270 CW
    10511103    if( $self->auto_rotate and $orientation =~ m/Rotate (\d+)/ ){
     1104        $bModifyOriginal = 1;
     1105        $bRotate = 1;
     1106    }
     1107
     1108    if( $self->watermark_activate_pwg_high ){
     1109        $bModifyOriginal = 1;
     1110        $bAddWatermark = 1;
     1111    }
     1112
     1113    if($bModifyOriginal){
     1114        $self-> _set_site_high_file ();
     1115
     1116        my $image = Image::Magick->new();
     1117        # we read original
     1118        my $status = $image->Read(
     1119            $self->current_image->file
     1120        );
     1121        warn "$status ", $self->current_image->file, "\n" if $status ;
     1122        return 0 if $status;
     1123
     1124        if($bRotate){
     1125            $image->Rotate( degrees=>$1 );     
     1126        }       
     1127        $image->Write(
     1128            filename=>encode('iso-8859-1', $self->current_image->site_high_file)
     1129        );
     1130        warn "$status ", $self->current_image->site_high_file, "\n" if $status ;
     1131        return 0 if $status;
     1132       
     1133        undef $image;
     1134
     1135        if($bAddWatermark){
     1136          my $file_out = $self->current_image->site_high_file;
     1137          $self->CreateWatermark(
     1138             $self->watermark_text,
     1139                $self->watermark_text_size,
     1140                $self->watermark_position,
     1141                $self->watermark_x,
     1142                $self->watermark_y,
     1143                $self->watermark_color,
     1144                $file_out
     1145            );
     1146        }
     1147
     1148
     1149        $self->_set_exif_tag(
     1150            $self->current_image->site_high_file,
     1151            'Orientation',
     1152            'Horizontal (normal)',
     1153        );
     1154
     1155        # Now all images that need to be rotated are done. Update exif
     1156        $self->current_image->exif_metadata->{Orientation} = 'Horizontal (normal)';
     1157
     1158
     1159    }
     1160    else{
     1161        # high file is the original file
     1162        $self->current_image->site_high_file(
     1163            $self->current_image->file
     1164        );
     1165    }
     1166
     1167    return 1;
     1168}
     1169
     1170# file name for original copy
     1171sub _set_site_high_file {
     1172        my ( $self ) = @_;
    10521173
    10531174        my ( $vol, $dir, $file ) = File::Spec->splitpath(
     
    10681189            )
    10691190        );
    1070 
    1071         my $image = Image::Magick->new();
    1072         # we read original
    1073         my $status = $image->Read(
    1074             $self->current_image->file
    1075         );
    1076         warn "$status ", $self->current_image->file, "\n" if $status ;
    1077         return 0 if $status;
    1078 
    1079         $image->Rotate( degrees=>$1 ); 
    1080        
    1081         $image->Write(
    1082             filename=>encode('iso-8859-1', $self->current_image->site_high_file)
    1083         );
    1084         warn "$status ", $self->current_image->site_high_file, "\n" if $status ;
    1085         return 0 if $status;
    1086        
    1087         undef $image;
    1088 
    1089         $self->_set_exif_tag(
    1090             $self->current_image->site_high_file,
    1091             'Orientation',
    1092             'Horizontal (normal)',
    1093         );
    1094 
    1095         # Now all images that need to be rotated are done. Update exif
    1096         $self->current_image->exif_metadata->{Orientation} = 'Horizontal (normal)';
    1097     }
    1098     else{
    1099         # high file is the original file
    1100         $self->current_image->site_high_file(
    1101             $self->current_image->file
    1102         );
    1103     }
    1104 
    1105     return 1;
     1191}
     1192
     1193sub CreateWatermark {
     1194    my ( $self, $text, $text_size, $position, $x, $y, $color, $file_out ) = @_;
     1195   
     1196    my $rval = 1 ;
     1197    my $gravity = $self->gravity->{$position};
     1198    my $fill = $self->rgbcolor->{$color};
     1199
     1200    # debug
     1201    printf("Create watermark %s\n", $file_out);
     1202
     1203   
     1204
     1205    my $image = new Image::Magick;
     1206   
     1207    my $status = $image->ReadImage(
     1208        encode('iso-8859-1', $file_out)
     1209    );     
     1210printf("gravity %s, color %s, pointsize %s, x %s, y %s\n", $gravity, $fill, $text_size, $x, $y);   
     1211    my $ratio = $image->Get('height')/($self->resize_h||$image->Get('height'));
     1212    $ratio||=1;
     1213    $text ||="Your watermark";
     1214    $image->Annotate(
     1215#        font => 'Vera.ttf',
     1216        pointsize => $text_size*$ratio,
     1217        fill => $fill,
     1218        x => $x*$ratio,
     1219        y => $y*$ratio,
     1220        text => $text,
     1221        gravity => $gravity,
     1222    );
     1223                     
     1224    $image->Write(
     1225        sprintf(
     1226            "%s:%s",
     1227            $self->type,
     1228            encode('iso-8859-1', $file_out),
     1229        )
     1230    );
    11061231}
    11071232
Note: See TracChangeset for help on using the changeset viewer.