Ignore:
Timestamp:
2011-09-15T16:31:11+12:00 (13 years ago)
Author:
ak19
Message:

Added gs-magick.pl script which will set the environment for ImageMagick (including LD_LIBRARY_PATH) before launching the requested ImageMagick command and arguments. By setting the Imagemagick environment from this script we ensure that the modified env variables don't create conflicts with libraries needed for normal linux execution. All the Greenstone files in the *binary* that made direct calls to imagemagick now go through this script. The affected files are perl files in bin/script and perllib and Gatherer.java of GLI. (wvware has files that test for imagemagick during compilation stage, which is independent of our changs which are only for users running imagemagick from a GS binary.) The final problems were related to how different perl files made use of the return values and the output of running their imagemagick command: they would query the 127 and/or and/or run the command with backtick operators to get the output printed to STDOUT. By inserting an intermediate gs-magick.pl file, needed to ensure that the exit code stored in 127 would at least be passed on correctly, as is necessary when testing the exit code against non-zero values or greater/less than zero (instead of comparing them with equals/not equal to 0). To get the correct exit code as emitted by imagemagick, calling code needs to shift bits in 127 and converting it to a signed value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/ImageConverter.pm

    r24346 r24600  
    3232no strict 'refs'; # allow filehandles to be variables and viceversa
    3333
     34use util;
    3435use gsprintf 'gsprintf';
    3536
     
    131132    $no_image_conversion_reason = "win95notsupported";
    132133    } else {
    133     my $result = `identify -help 2>&1`;
     134    my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
     135    my $result = `$imagick_cmd identify -help 2>&1`;
    134136    my $return_value = $?;
    135  
    136     if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) {  # Linux and Windows return different values for "program not found"
     137
     138    # When testing against non-zero return_value ($?), need to shift by 8
     139    # and convert it to its signed value. Linux returns -1 and Windows returns
     140    # 256 for "program not found". The signed equivalents are -1 and 1 respectively.
     141    $return_value >>= 8;
     142    $return_value = (($return_value & 0x80) ? -(0x100 - ($return_value & 0xFF)) : $return_value);
     143
     144    if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 1) || $return_value == -1) {  # Linux and Windows return different values for "program not found"
    137145        $image_conversion_available = 0;
    138146        $no_image_conversion_reason = "imagemagicknotinstalled";
     
    407415
    408416    # Generate and run the convert command
    409     my $convert_command = "convert -interlace plane -verbose $convert_options \"$source_file_path\" \"$target_file_path\"";
     417    my $convert_command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl convert -interlace plane -verbose $convert_options \"$source_file_path\" \"$target_file_path\"";
    410418
    411419    my $print_info = { 'message_prefix' => $convert_id,
     
    439447
    440448    # Use the ImageMagick "identify" command to get the file specs
    441     my $command = "identify \"$image\" 2>&1";
     449    my $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$image\" 2>&1";
    442450    print $outhandle "$command\n" if ($verbosity > 2);
    443451    my $result = '';
Note: See TracChangeset for help on using the changeset viewer.