Index: /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 24599)
+++ /main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 24600)
@@ -439,27 +439,4 @@
 			}
 
-			// Check for ImageMagick
-			if (Gatherer.isGsdlRemote) {
-				DebugStream.println("Not checking for ImageMagick.");
-			}
-			else if (!(new ImageMagickTest()).found()) {
-				// Time for a warning message
-				missingImageMagick();
-			}
-			
-			// Check for PDFBox
-			if (Gatherer.isGsdlRemote) {
-				DebugStream.println("Not checking for PDFBox.");
-			}
-			else {
-			    String gs_dir = GS3 ? gsdl3_src_path : gsdl_path;
-			    File pdfboxExtensionFolder = new File(gs_dir+File.separator+"ext"+File.separator+"pdf-box");
-			    if (!(pdfboxExtensionFolder.exists() && pdfboxExtensionFolder.isDirectory())) {
-				// The user doesn't have PDFBox, inform them of it
-				String zipExtension = Utility.isWindows() ? "zip" : "tar.gz";
-				missingPDFBox(zipExtension, pdfboxExtensionFolder.getParent());
-			    }
-			}
-
 
 			if (Gatherer.isGsdlRemote) {
@@ -490,4 +467,28 @@
 					missingPERL();
 				}
+			}
+
+
+			// Check for ImageMagick - dependent on perl_path
+			if (Gatherer.isGsdlRemote) {
+				DebugStream.println("Not checking for ImageMagick.");
+			}
+			else if (!(new ImageMagickTest()).found()) {
+				// Time for a warning message
+				missingImageMagick();
+			}
+			
+			// Check for PDFBox
+			if (Gatherer.isGsdlRemote) {
+				DebugStream.println("Not checking for PDFBox.");
+			}
+			else {
+			    String gs_dir = GS3 ? gsdl3_src_path : gsdl_path;
+			    File pdfboxExtensionFolder = new File(gs_dir+File.separator+"ext"+File.separator+"pdf-box");
+			    if (!(pdfboxExtensionFolder.exists() && pdfboxExtensionFolder.isDirectory())) {
+				// The user doesn't have PDFBox, inform them of it
+				String zipExtension = Utility.isWindows() ? "zip" : "tar.gz";
+				missingPDFBox(zipExtension, pdfboxExtensionFolder.getParent());
+			    }
 			}
 
@@ -1563,9 +1564,37 @@
 		public boolean found()
 		{
+		    // at this stage, GLI has already sourced setup.bash, and the necessary
+		    // env variables will be available to the perl process we're about to launch
+		    boolean found = false;
+
 			try {
-				String[] command = new String[2];
-				command[0] = (Utility.isWindows() ? "identify.exe" : "identify");
-				command[1] = "-version";
-				Process image_magick_process = Runtime.getRuntime().exec(command);
+			    // run the command `/path/to/perl -S gs-magick.pl identify -version`
+			    ArrayList cmd_list = new ArrayList();
+			    if (!Gatherer.isGsdlRemote) {
+				if(Configuration.perl_path != null) {
+				    cmd_list.add(Configuration.perl_path);
+				} else {
+				    System.err.println("***** ImageMagickTest Warning: Perl_path not set, calling 'perl' instead.");
+				    cmd_list.add("perl");
+				}
+				cmd_list.add("-S");
+			    }
+			    cmd_list.add("gs-magick.pl");
+			    if(Utility.isWindows()) {
+				cmd_list.add("identify.exe");
+			    } else {
+				cmd_list.add("identify");
+			    }
+			    cmd_list.add("-version");
+
+			    String[] command_parts = (String[]) cmd_list.toArray(new String[0]);
+
+			    String cmd_str = "";
+			    for(int i = 0; i < command_parts.length; i++) {
+			    	cmd_str += command_parts[i] + " ";
+			    }
+			    DebugStream.println("***** Running ImageMagickTest command: " + cmd_str);
+
+				Process image_magick_process = Runtime.getRuntime().exec(command_parts);
 				image_magick_process.waitFor();
 
@@ -1574,24 +1603,24 @@
 
 				BufferedReader br = new BufferedReader(isr);
-				// Capture the standard output stream and seach for two particular occurances: Version and ImageMagick.
+				// Capture the standard output stream and seach for two particular occurrences: Version and ImageMagick.
 
 				String line = br.readLine();
-				if (line == null) {
-					return false;
-				}
-				String lc_line = line.toLowerCase();
-				if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
-					return true;
-				} else {
-					return false;
-				}
-
+				if (line != null) {
+				    String lc_line = line.toLowerCase();
+				    if (lc_line.indexOf("version") != -1 || lc_line.indexOf("imagemagick") != -1) {
+					//System.err.println("*** ImageMagickTest Line: " + line);
+					found = true;
+				    } // else found var remains false
+				}
+
+				// Maybe put the close in a finally (but note that it can throw and IOex too)? See
+				// http://download.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
+				br.close();
+				return found;
 				//return (image_magick_process.exitValue() == 0);
 			}
-			catch (IOException exception) {
-				return false;
-			}
-			catch (InterruptedException exception) {
-				return false;
+			catch (Exception exception) {	
+			    exception.printStackTrace();
+			    return found;
 			}
 		}
Index: /main/trunk/greenstone2/bin/script/gs-magick.pl
===================================================================
--- /main/trunk/greenstone2/bin/script/gs-magick.pl	(revision 24600)
+++ /main/trunk/greenstone2/bin/script/gs-magick.pl	(revision 24600)
@@ -0,0 +1,156 @@
+#!/usr/bin/perl -w
+
+###########################################################################
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2009 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+
+# gs-magick.pl:
+# Script to set the environment for imagemagick and then run it, returning
+# both the exit code and printing the output to STDOUT.
+# Setting the env vars necessary for imagemagick here locally means 
+# they won't interfere with the normal environment it would have 
+# if the environment had been set in setup.bash/setup.bat instead
+
+
+BEGIN {
+    die "GSDLHOME not set - run the (gs3-)setup script\n" unless defined $ENV{'GSDLHOME'};
+    die "GSDLOS not set - run (gs3-)setup script\n" unless defined $ENV{'GSDLOS'};
+    die "GSDLARCH not set - run (gs3-)setup script\n" unless defined $ENV{'GSDLARCH'};
+
+    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
+}
+
+
+use strict;
+no strict 'refs'; # make an exception so we can use variables as filehandles
+use util;
+
+
+sub main
+{
+    my ($argc,@argv) = @_;
+
+    my $usage = "Usage: $0 [--usage|--verbosity <num>] <imagick-command> <arguments to imagick command>";
+
+    my $verbosity = 0;
+    my $magick_cmd = "";
+
+
+    # Construct the imagemagick cmd string from all the arguments, 
+    # embedding any arguments that contain spaces in quotes.
+    # We'll remove the --options afterwards. 
+    my $count = 0;
+    for ($count = 0; $count < scalar(@argv); $count++) {
+	if($argv[$count] =~ m/ /) { 
+	    $argv[$count] = "\"".$argv[$count]."\"";
+	}
+	$magick_cmd = "$magick_cmd $argv[$count]"; 
+    }
+
+    # process the --options in the imagemagick command
+    # Tried using the official GetOptions module to parse options, except that
+    # the --verbosity|--v option to gs-magick.pl interfered with the -verbose 
+    # option that image-magick accepts.
+
+    if($magick_cmd =~ m/--usage/) {
+	print STDERR "$usage\n";
+	exit(0);
+    }
+
+    $magick_cmd =~ s/\s*--verbosity(\s+|=)(\d*)\s*/ /; # --verbosity=4 or --verbosity   4
+    $verbosity = $2 if defined $2; # print STDERR "subst 2 is : $2\n" if defined $2; 
+
+    if($verbosity > 2) {
+	print STDERR "***** Running MAGICK_CMD: $magick_cmd\n";
+	#print STDERR "***** verbosity: $verbosity\n";
+    }
+
+    ## SET THE ENVIRONMENT AS USED TO BE DONE IN SETUP.BASH/BAT
+    
+    my $magick_home = &util::filename_cat($ENV{'GSDLHOME'},"bin",$ENV{'GSDLOS'}.$ENV{'GSDLARCH'},"imagemagick");
+    if (-d $magick_home) { # "$GSDLHOME/bin/$GSDLOS$GSDLARCH/imagemagick"
+	$ENV{'MAGICK_HOME'} = $magick_home;
+    }
+    
+    # if Greenstone came with imagick, or if the user otherwise has an 
+    # imagick to fall back on (and set MAGICK_HOME that way) we use that
+    if(defined $ENV{'MAGICK_HOME'} && -d $ENV{'MAGICK_HOME'}) {
+	&util::envvar_prepend("PATH", &util::filename_cat($ENV{'MAGICK_HOME'}, "bin"));
+
+	my $magick_lib = &util::filename_cat($ENV{'MAGICK_HOME'}, "lib");
+	if($ENV{'GSDLOS'} eq "linux") {
+	    &util::envvar_prepend("LD_LIBRARY_PATH", $magick_lib);
+	} elsif ($ENV{'GSDLOS'} eq "darwin") {
+	    &util::envvar_prepend("DYLD_LIBRARY_PATH", $magick_lib);
+	}
+
+	if($verbosity > 2) {
+	    print STDERR "\t*** MAGICK_HOME".$ENV{'MAGICK_HOME'}."\n";
+	    print STDERR "\t*** LD_LIB_PATH".$ENV{'LD_LIBRARY_PATH'}."\n";
+	    print STDERR "\t*** PATH".$ENV{'PATH'}."\n\n";
+	}
+    }
+
+    # if no MAGICK_HOME, maybe they want to run with the system imagemagick
+    elsif($verbosity > 2) {
+	print STDERR "**** No ImageMagick in Greenstone. Will try to use any imagemagick on the system.\n\n";
+    }
+
+    # RUN THE IMAGEMAGICK COMMAND
+    
+    # John Thompson's manner of using backticks to preserve the output of
+    # running imagemagick. 
+    # $? contains the exit code of running the imagemagick command. 
+    # This needs to be shifted by 8 and then converted to be a signed value
+    # to work out the actual exit code value.
+
+    #my $result = `$magick_cmd`; # This way will trap STDOUT into local variable
+
+    if (!open(PIN, "$magick_cmd |")) {
+	print STDERR "*** Can't run $magick_cmd. Error was: $!";
+    }
+    my $result = "";
+    while (defined (my $imagick_output_line = <PIN>)) {
+	$result = $result.$imagick_output_line;
+    }
+    close(PIN);
+   
+    # Perl Special Variables http://www.kichwa.com/quik_ref/spec_variables.html
+    # $? The status returned by the last pipe close, backtick(``) command or system operator. 
+    # Note that this is the status word returned by the wait() system call, so the exit value 
+    # of the subprocess is actually ($? >>*). $? & 255 gives which signal, if any, the process
+    # died from, and whether there was a core dump. 
+
+    # Shift by 8 to get a value between 0 and 255, then work out if it is signed or unsigned
+    # http://stackoverflow.com/questions/2726447/why-is-the-exit-code-255-instead-of-1-in-perl    
+    my $status = $?;
+    $status >>= 8;
+    $status = (($status & 0x80) ? -(0x100 - ($status & 0xFF)) : $status);
+
+    # send the output to STDOUT, since calling functions may call gs-magick.pl with backticks
+    print STDOUT $result;
+    exit($status);
+}
+
+&main(scalar(@ARGV),@ARGV);
Index: /main/trunk/greenstone2/bin/script/gsConvert.pl
===================================================================
--- /main/trunk/greenstone2/bin/script/gsConvert.pl	(revision 24599)
+++ /main/trunk/greenstone2/bin/script/gsConvert.pl	(revision 24600)
@@ -824,6 +824,18 @@
     # Check that ImageMagick is installed and available on the path (except for Windows 95/98)
     if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
-	my $result = `identify 2>&1`;
-	if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
+	my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
+	my $result = `$imagick_cmd identify 2>&1`;
+
+	# Linux and Windows return different values for "program not found".
+	# Linux returns -1 and Windows 256 for "program not found". But once they're
+	# converted to signed values, it will be -1 for Linux and 1 for Windows.
+	# Whenever we test for return values other than 0, shift by 8 and perform 
+	# unsigned to signed status conversion on $? to get expected range of return vals
+	# Although gs-magick.pl already shifts its $? by 8, converts it to a signed value
+	# and then exits on that, by the time we get here, we need to do it again
+	my $status = $?;
+	$status >>= 8;
+	$status = (($status & 0x80) ? -(0x100 - ($status & 0xFF)) : $status);	
+	if ($status == -1 || $status == 1) { #if ($status == -1 || $status == 256) {
 	    #ImageMagick is not installed, thus the convert utility is not available. 
 	    print STDERR "*** ImageMagick is not installed, the convert utility is not available. Unable to convert PDF/PS to images\n";
Index: /main/trunk/greenstone2/bin/script/pdfpstoimg.pl
===================================================================
--- /main/trunk/greenstone2/bin/script/pdfpstoimg.pl	(revision 24599)
+++ /main/trunk/greenstone2/bin/script/pdfpstoimg.pl	(revision 24600)
@@ -88,5 +88,5 @@
     # with quoting when GSDLHOME might contain spaces) but assume
     # that the PATH is set up correctly.
-    $cmd = "convert";
+    $cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl convert";
 
     my $output_filename = &util::filename_cat($output_filestem, $input_basename);
@@ -100,5 +100,6 @@
     # note we return 0 if the file is "encrypted"
     $!=0;
-    if (system($cmd)!=0) {
+    my $status = system($cmd);
+    if ($status != 0) {
 	print STDERR "Convert error for $input_filename $!\n";
 	# leave these for gsConvert.pl...
Index: /main/trunk/greenstone2/bin/script/pdftohtml.pl
===================================================================
--- /main/trunk/greenstone2/bin/script/pdftohtml.pl	(revision 24599)
+++ /main/trunk/greenstone2/bin/script/pdftohtml.pl	(revision 24600)
@@ -249,5 +249,5 @@
 	    $cmd = "pnmtopng \"${directory}$image\" > \"${directory}$image_base.png\" 2>/dev/null";
 	    if (system($cmd)!=0) {
-		$cmd = "convert \"${directory}$image\" \"${directory}$image_base.png\" 2>/dev/null";
+		$cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl convert \"${directory}$image\" \"${directory}$image_base.png\" 2>/dev/null";
 		if (system($cmd)!=0) {
 		    print STDERR "Cannot convert $image into PNG format (tried `pnmtopng' and `convert')...\n";
Index: /main/trunk/greenstone2/perllib/cgiactions/imageaction.pm
===================================================================
--- /main/trunk/greenstone2/perllib/cgiactions/imageaction.pm	(revision 24599)
+++ /main/trunk/greenstone2/perllib/cgiactions/imageaction.pm	(revision 24600)
@@ -29,4 +29,5 @@
 
 use cgiactions::baseaction;
+use util;
 
 @imageaction::ISA = ('baseaction');
@@ -158,5 +159,5 @@
 
 
-	my $cmd = "convert \"$src_full_assoc_filename\" ";
+	my $cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl convert \"$src_full_assoc_filename\" ";
 	$cmd .= "-rotate 90 " if ($orientation eq "landscape");
 
Index: /main/trunk/greenstone2/perllib/convertutil.pm
===================================================================
--- /main/trunk/greenstone2/perllib/convertutil.pm	(revision 24599)
+++ /main/trunk/greenstone2/perllib/convertutil.pm	(revision 24600)
@@ -175,6 +175,12 @@
 	if ($command_status != 0) {
 	    $had_error = 1;
-
-	    print $outhandle "Error: processing command failed.  Exit status $?\n";
+	    
+	    # for imagemagick commands that go via gs-magick.pl, need to shift exit code by 8 and then 
+	    # convert to its signed value to get the actual exit code that imagemagick had emitted.
+	    my $signed_cmd_status = $command_status;
+	    $signed_cmd_status >>= 8;
+	    $signed_cmd_status = (($signed_cmd_status & 0x80) ? -(0x100 - ($signed_cmd_status & 0xFF)) : $signed_cmd_status);	
+
+	    print $outhandle "Error: processing command failed.  Exit status $command_status (signed value: $signed_cmd_status)\n";
 
 	    if ($verbosity >= 3) {
Index: /main/trunk/greenstone2/perllib/giget.pm
===================================================================
--- /main/trunk/greenstone2/perllib/giget.pm	(revision 24599)
+++ /main/trunk/greenstone2/perllib/giget.pm	(revision 24600)
@@ -1,3 +1,4 @@
 use strict;
+use util;
 
 
@@ -150,31 +151,40 @@
 		unlink $output_fname;
 	    }
-	    elsif (system("identify \"$output_fname\"") > 0 ) {
-		print STDERR "**** NOT JPEG: output_fname \n";
-		unlink $output_fname;
-	    }
 	    else {
-
-		my $command = "identify \"$output_fname\" 2>&1";
-		my $result = `$command`;
-
-		my $type =   'unknown';
-		my $width =  'unknown';
-		my $height = 'unknown';
-		
-		my $image_safe = quotemeta $output_fname;
-		if ($result =~ /^$image_safe (\w+) (\d+)x(\d+)/) {
-		    $type = $1;
-		    $width = $2;
-		    $height = $3;
+		# need to shift the $? exit code returned by system() by 8 bits and
+		# then convert it to a signed value to work out whether it is indeed > 0
+		my $status = system("\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\"");
+		$status >>= 8;
+		$status = (($status & 0x80) ? -(0x100 - ($status & 0xFF)) : $status);
+
+		if($status > 0 ) {
+		    print STDERR "**** NOT JPEG: output_fname \n";
+		    unlink $output_fname;
+		} 
+		else {
+		    my $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\" 2>&1";
+		    my $result = `$command`;
+		    
+		    my $type =   'unknown';
+		    my $width =  'unknown';
+		    my $height = 'unknown';
+		    
+		    my $image_safe = quotemeta $output_fname;
+		    if ($result =~ /^$image_safe (\w+) (\d+)x(\d+)/) {
+			$type = $1;
+			$width = $2;
+			$height = $3;
+		    }
+		    
+		    my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
+		    
+		    if (($width ne "unknown") && ($height ne "unknown")) {
+			if (($width>200) || ($height>200)) {
+			    `$imagick_cmd convert \"$output_fname\" -resize 200x200 /tmp/x.jpg`;
+			    `/bin/mv /tmp/x.jpg \"$output_fname\"`;
+			}
+		    }
+		    $c++;
 		}
-
-		if (($width ne "unknown") && ($height ne "unknown")) {
-		    if (($width>200) || ($height>200)) {
-			`convert \"$output_fname\" -resize 200x200 /tmp/x.jpg`;
-			`/bin/mv /tmp/x.jpg \"$output_fname\"`;
-		    }
-		}
-		$c++;
 	    }
 
Index: /main/trunk/greenstone2/perllib/plugins/HTMLImagePlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/HTMLImagePlugin.pm	(revision 24599)
+++ /main/trunk/greenstone2/perllib/plugins/HTMLImagePlugin.pm	(revision 24600)
@@ -451,4 +451,7 @@
     my ($filename, $orig_fp, $fn, $ext, $reltext, $relreltext, $crcid, $imgs,
 	$thumbfp, $pagetitle, $alttext,	$filepath, $aggr);
+
+    my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
+
     $aggr = $self->{'aggressiveness'};
     $imgs = \%{$self->{'imglist'}};
@@ -463,5 +466,5 @@
     ($fn, $ext) = $onlyfn =~ /(.*)\.(.*)/;
     $fn = lc $fn; $ext = lc $ext;
-    ($reltext) = "<tr><td>GifComment</td><td>" . `identify $filepath -ping -format "%c"` . "</td></tr>\n"
+    ($reltext) = "<tr><td>GifComment</td><td>" . `$imagick_cmd identify $filepath -ping -format "%c"` . "</td></tr>\n"
         if ($ext eq "gif");
     $reltext .= "<tr><td>FilePath</td><td>$orig_fp</td></tr>\n";
@@ -469,7 +472,10 @@
     if ($ENV{'GSDLOS'} =~ /^windows$/i) {
 	$crcid = "$fn.$ext." . $self->{'next_crcid'}++;
-    } else { ($crcid) = `cksum $filepath` =~ /^(\d+)/; }
+    } else { 
+	($crcid) = `cksum $filepath` =~ /^(\d+)/; 
+    }
+    
     $thumbfp = "$tndir/tn_$crcid.jpg";
-    `convert -flatten -filter Hanning $self->{'convert_params'} -geometry "$self->{'thumb_size'}x$self->{'thumb_size'}>" $filepath $thumbfp` unless -e $thumbfp;
+    `$imagick_cmd convert -flatten -filter Hanning $self->{'convert_params'} -geometry "$self->{'thumb_size'}x$self->{'thumb_size'}>" $filepath $thumbfp` unless -e $thumbfp;
     if ( ! (-e $thumbfp) ) {
 	print STDERR "HTMLImagePlugin: 'convert' failed. Check ImageMagicK binaries are installed and working correctly\n"; return 0; 
@@ -983,6 +989,7 @@
 	# can't modify real filepath var because it
 	# then can't be located in the page for tag recognition later
+	my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
 	($width, $height) = 
-	    `identify $abspath -ping -format "%wx%h"` =~ /^(\d*)x(\d*)$/m;
+	    `$imagick_cmd identify $abspath -ping -format "%wx%h"` =~ /^(\d*)x(\d*)$/m;
 	if (! ($width && $height)) { 
 	    print STDERR "HTMLImagePlugin: ($abspath) 'identify' failed. Check ImageMagicK binaries are installed and working correctly\n"; next;
Index: /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 24599)
+++ /main/trunk/greenstone2/perllib/plugins/ImageConverter.pm	(revision 24600)
@@ -32,4 +32,5 @@
 no strict 'refs'; # allow filehandles to be variables and viceversa
 
+use util;
 use gsprintf 'gsprintf';
 
@@ -131,8 +132,15 @@
 	$no_image_conversion_reason = "win95notsupported";
     } else {
-	my $result = `identify -help 2>&1`;
+	my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
+	my $result = `$imagick_cmd identify -help 2>&1`;
 	my $return_value = $?;
- 
-	if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) {  # Linux and Windows return different values for "program not found"
+
+	# When testing against non-zero return_value ($?), need to shift by 8 
+	# and convert it to its signed value. Linux returns -1 and Windows returns 
+	# 256 for "program not found". The signed equivalents are -1 and 1 respectively.
+	$return_value >>= 8;
+	$return_value = (($return_value & 0x80) ? -(0x100 - ($return_value & 0xFF)) : $return_value);
+
+	if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 1) || $return_value == -1) {  # Linux and Windows return different values for "program not found"
 	    $image_conversion_available = 0;
 	    $no_image_conversion_reason = "imagemagicknotinstalled";
@@ -407,5 +415,5 @@
 
     # Generate and run the convert command
-    my $convert_command = "convert -interlace plane -verbose $convert_options \"$source_file_path\" \"$target_file_path\"";
+    my $convert_command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl convert -interlace plane -verbose $convert_options \"$source_file_path\" \"$target_file_path\"";
 
     my $print_info = { 'message_prefix' => $convert_id,
@@ -439,5 +447,5 @@
 
     # Use the ImageMagick "identify" command to get the file specs
-    my $command = "identify \"$image\" 2>&1";
+    my $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$image\" 2>&1";
     print $outhandle "$command\n" if ($verbosity > 2);
     my $result = '';
Index: /main/trunk/greenstone2/perllib/plugins/StructuredHTMLPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/StructuredHTMLPlugin.pm	(revision 24599)
+++ /main/trunk/greenstone2/perllib/plugins/StructuredHTMLPlugin.pm	(revision 24600)
@@ -36,4 +36,5 @@
 use HTMLPlugin;
 use ImageConverter; # want the identify method
+use util;
 
 use strict; # every perl program should have this!
@@ -327,4 +328,5 @@
 	    my $command = "convert -interlace plane -verbose "
 		."-geometry $newsize \"$img_filename\" \"$resized_filename\"";
+	    $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl $command";
 	    #print $outhandle "ImageResize: $command\n" if ($verbosity > 2);
 	    #my $result = '';
