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/giget.pm

    r15889 r24600  
    11use strict;
     2use util;
    23
    34
     
    150151        unlink $output_fname;
    151152        }
    152         elsif (system("identify \"$output_fname\"") > 0 ) {
    153         print STDERR "**** NOT JPEG: output_fname \n";
    154         unlink $output_fname;
    155         }
    156153        else {
    157 
    158         my $command = "identify \"$output_fname\" 2>&1";
    159         my $result = `$command`;
    160 
    161         my $type =   'unknown';
    162         my $width =  'unknown';
    163         my $height = 'unknown';
    164        
    165         my $image_safe = quotemeta $output_fname;
    166         if ($result =~ /^$image_safe (\w+) (\d+)x(\d+)/) {
    167             $type = $1;
    168             $width = $2;
    169             $height = $3;
     154        # need to shift the $? exit code returned by system() by 8 bits and
     155        # then convert it to a signed value to work out whether it is indeed > 0
     156        my $status = system("\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\"");
     157        $status >>= 8;
     158        $status = (($status & 0x80) ? -(0x100 - ($status & 0xFF)) : $status);
     159
     160        if($status > 0 ) {
     161            print STDERR "**** NOT JPEG: output_fname \n";
     162            unlink $output_fname;
     163        }
     164        else {
     165            my $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\" 2>&1";
     166            my $result = `$command`;
     167           
     168            my $type =   'unknown';
     169            my $width =  'unknown';
     170            my $height = 'unknown';
     171           
     172            my $image_safe = quotemeta $output_fname;
     173            if ($result =~ /^$image_safe (\w+) (\d+)x(\d+)/) {
     174            $type = $1;
     175            $width = $2;
     176            $height = $3;
     177            }
     178           
     179            my $imagick_cmd = "\"".&util::get_perl_exec()."\" -S gs-magick.pl";
     180           
     181            if (($width ne "unknown") && ($height ne "unknown")) {
     182            if (($width>200) || ($height>200)) {
     183                `$imagick_cmd convert \"$output_fname\" -resize 200x200 /tmp/x.jpg`;
     184                `/bin/mv /tmp/x.jpg \"$output_fname\"`;
     185            }
     186            }
     187            $c++;
    170188        }
    171 
    172         if (($width ne "unknown") && ($height ne "unknown")) {
    173             if (($width>200) || ($height>200)) {
    174             `convert \"$output_fname\" -resize 200x200 /tmp/x.jpg`;
    175             `/bin/mv /tmp/x.jpg \"$output_fname\"`;
    176             }
    177         }
    178         $c++;
    179189        }
    180190
Note: See TracChangeset for help on using the changeset viewer.