Index: /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 26865)
+++ /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 26866)
@@ -94,5 +94,41 @@
 	'deft' => "100",
 	'range' => "1,",
-	'reqd' => "no" }
+	'reqd' => "no" },
+
+      { 'name' => "apply_aspectpad",
+	'desc' => "{ImageConverter.apply_aspectpad}",
+	'type' => "enum",
+	'list' => [{'name' => "true", 'desc' => "{common.true}"},
+		   {'name' => "false", 'desc' => "{common.false}"}],
+	'deft' => "false",
+	'reqd' => "no" },
+      { 'name' => "aspectpad_ratio",
+	'desc' => "{ImageConverter.aspectpad_ratio}",
+	'type' => "string",
+	'deft' => "2",
+	'range' => "1,",
+	'reqd' => "no" },
+      { 'name' => "aspectpad_mode",
+	'desc' => "{ImageConverter.aspectpad_mode}",
+	'type' => "enum",
+	'list' => [{'name' => "al", 'desc' => "{aspectpad.al}"},
+		   {'name' => "ap", 'desc' => "{aspectpad.ap}"},
+		   {'name' => "l",  'desc' => "{aspectpad.l}"},
+		   {'name' => "p",  'desc' => "{aspectpad.p}"}],
+	'deft' => "al",
+	'reqd' => "no" },
+      { 'name' => "aspectpad_colour",
+	'desc' => "{ImageConverter.aspectpad_colour}",
+	'type' => "string",
+	'deft' => "transparent",
+	'reqd' => "no" },
+      { 'name' => "aspectpad_tolerance",
+	'desc' => "{ImageConverter.aspectpad_tolerance}",
+	'type' => "string",
+	'deft' => "0.0",
+	'range' => "0,",
+	'reqd' => "no" },
+
+
 		 ];
 
@@ -213,8 +249,9 @@
     my $url_to_filehead = &unicode::filename_to_url($filehead);
     my $url_to_filename_no_path = &unicode::filename_to_url($filename_no_path);
-    
+
+    my $type = "unknown";
+
     # Convert the image to a new type (if required).
     my $converttotype = $self->{'converttotype'};
-    my $type = "unknown";
 
     if ($converttotype ne "" && $filename_full_path !~ m/$converttotype$/) {
@@ -232,4 +269,29 @@
 	}
     }
+
+    # Apply aspect padding (if required).
+    my $apply_aspectpad = $self->{'apply_aspectpad'};
+
+    if ($apply_aspectpad eq "true") {
+	my $aspectpad_ratio     = $self->{'aspectpad_ratio'};
+	my $aspectpad_mode      = $self->{'aspectpad_mode'};
+	my $aspectpad_colour    = $self->{'aspectpad_colour'};
+	my $aspectpad_tolerance = $self->{'aspectpad_tolerance'};
+
+	($type) = ($filename_full_path =~ m/\.(.*?)$/);
+	##$type = lc($type);
+
+	my ($result, $aspectpad_filename_full_path)
+	    = $self->aspectpad($filename_full_path, $type, $aspectpad_ratio, $aspectpad_mode, 
+			       $aspectpad_colour, $aspectpad_tolerance, "", "ASPECTPAD");
+
+	$filename_full_path = $aspectpad_filename_full_path;
+
+	if ($self->{'store_file_paths'}) {
+	    $self->{'orig_file'} = $aspectpad_filename_full_path;
+	}
+    }
+    
+
 
     # add Image metadata 
@@ -428,4 +490,5 @@
 }
 
+
 sub convert_without_result {
     my $self = shift(@_);
@@ -439,4 +502,53 @@
 			  $convert_options,$convert_id,"without_result");
 }
+
+
+sub aspectpad {
+    my $self = shift(@_);
+    my $source_file_path     = shift(@_);
+    my $target_file_type     = shift(@_);
+    my $aspectpad_ratio      = shift(@_);
+    my $aspectpad_mode       = shift(@_); 			       
+    my $aspectpad_colour     = shift(@_);
+    my $aspectpad_tolerance  = shift(@_);
+
+    my $aspectpad_options  = shift(@_) || "";
+    my $aspectpad_id       = shift(@_) || "";
+    my $cache_mode       = shift(@_) || "";
+
+    my $outhandle = $self->{'outhandle'};
+    my $verbosity = $self->{'verbosity'};
+
+    my $source_file_no_path = &File::Basename::basename($source_file_path);
+
+    # Determine the full name and path of the output file
+    my $target_file_path;
+    if ($self->{'enable_cache'}) {
+	my $cached_image_dir = $self->{'cached_dir'};
+	my $image_root = $self->{'cached_file_root'};
+	$image_root .= "_$aspectpad_id" if ($aspectpad_id ne "");
+	my $image_file = "$image_root.$target_file_type";
+	$target_file_path = &util::filename_cat($cached_image_dir,$image_file);
+    }
+    else {
+	$target_file_path = &util::get_tmp_filename($target_file_type);
+	push(@{$self->{'tmp_file_paths'}}, $target_file_path);
+    }
+
+    # Generate and run the aspectpad command
+    my $aspectpad_command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl --verbosity=".$self->{'verbosity'}." aspectpad.sh -a $aspectpad_ratio -m $aspectpad_mode -p \"$aspectpad_colour\" -t $aspectpad_tolerance $aspectpad_options \"$source_file_path\" \"$target_file_path\"";
+
+    my $print_info = { 'message_prefix' => $aspectpad_id,
+		       'message' => "Aspect padding image $source_file_no_path to: $aspectpad_id $target_file_type" };
+    $print_info->{'cache_mode'} = $cache_mode if ($cache_mode ne "");
+
+    my ($regenerated,$result,$had_error) 
+	= $self->autorun_general_cmd($aspectpad_command,$source_file_path,$target_file_path,$print_info);
+
+    return ($result,$target_file_path);
+}
+
+
+
 
 
