Changeset 16008


Ignore:
Timestamp:
2008-06-16T11:11:44+12:00 (16 years ago)
Author:
kjdon
Message:

create_thumbnail and create_screenview are now enum with true and false values. TODO: make ImagePLugin and PagedImagePLugin set the defaults appropriately. put the imagemagick checking into init. TODO: do the checking also in new, and set a disabled flag to the options if they are not available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/plugins/ImageConverter.pm

    r15881 r16008  
    44
    55use strict;
     6use gsprintf 'gsprintf';
    67
    78BEGIN {
     
    1112my $arguments = [
    1213      { 'name' => "create_thumbnail",
    13     'desc' => "{ImageConverter.generatethumbnail}",
    14     'type' => "bool",
     14    'desc' => "{ImageConverter.create_thumbnail}",
     15    'type' => "enum",
     16    'list' => [{'name' => "true", 'desc' => "{ImageConverter.true}"},
     17           {'name' => "false", 'desc' => "{ImageConverter.false}"}],
    1518    'deft' => "true",
    16     'reqd' => "no" },
    17       { 'name' => "noscaleup",
    18     'desc' => "{ImageConverter.noscaleup}",
    19     'type' => "flag",
    2019    'reqd' => "no" },
    2120      { 'name' => "thumbnailsize",
     
    3029    'deft' => "gif",
    3130    'reqd' => "no" },
     31      { 'name' => "noscaleup",
     32    'desc' => "{ImageConverter.noscaleup}",
     33    'type' => "flag",
     34    'reqd' => "no" },
    3235      { 'name' => "create_screenview",
    33     'desc' => "{ImageConverter.generatescreenview}",
    34     'type' => "bool",
     36    'desc' => "{ImageConverter.create_screenview}",
     37    'type' => "enum",
     38    'list' => [{'name' => "true", 'desc' => "{ImageConverter.true}"},
     39           {'name' => "false", 'desc' => "{ImageConverter.false}"}],
    3540    'deft' => "true",
    3641    'reqd' => "no" },
     
    5156    'deft' => "",
    5257    'reqd' => "no" },
    53       { 'name' => "noscaleup",
    54     'desc' => "{ImageConverter.noscaleup}",
    55     'type' => "flag",
    56     'reqd' => "no" },
    5758      { 'name' => "minimumsize",
    5859    'desc' => "{ImageConverter.minimumsize}",
     
    8384    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
    8485
    85     # Check that ImageMagick is installed and available on the path (except for Windows 95/98)
    86     if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
     86    return bless $self, $class;
     87
     88}
     89
     90# needs to be called after BasePlugin init, so that outhandle is set up.
     91sub init {
     92    my $self = shift(@_);
     93
     94    $self->{'tmp_file_paths'} = ();
     95
     96    # Check that ImageMagick is installed and available on the path
     97    my $image_conversion_available = 1;
     98    my $no_image_conversion_reason = "";
     99    # None of this works very well on Windows 95/98...
     100    if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) {
     101    $image_conversion_available = 0;
     102    $no_image_conversion_reason = "win95notsupported";
     103    } else {
    87104    my $result = `identify 2>&1`;
    88105    if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
    89         $self->{'imagemagick_not_installed'} = 1;
    90     }
    91     }
    92     return bless $self, $class;
    93 
    94 }
    95 
    96 sub init {
    97     my $self = shift(@_);
    98 
    99     $self->{'tmp_file_paths'} = ();
    100 }
    101    
    102 sub check_imagemagick {
    103 
    104     my $self = shift (@_);
    105     my ($gli) = @_;
    106 
    107     my $outhandle = $self->{'outhandle'};
    108    
    109     my $image_magick_ok = 1;
    110     # None of this works very well on Windows 95/98...
    111     if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) {
    112     if ($gli) {
    113         #print STDERR "<ProcessingError n='$file' r='Windows 95/98 not supported'>\n";
    114         # have no file here. other kind of error? just want a warning really
    115     }
    116     print $outhandle "ImageConverter: Windows 95/98 not supported, no image processing available\n";
    117     $image_magick_ok = 0;
    118 
    119     } else {
    120     # Check that ImageMagick is installed and available on the path
    121     my $result = `identify 2>&1`;
    122     if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
    123         if ($gli) {
    124         #print STDERR "<ProcessingError n='$file' r='ImageMagick not installed'>\n";
    125         }
    126         print $outhandle "ImageConverter: ImageMagick not installed, no image processing available\n";
    127         $image_magick_ok = 0;
    128     }
    129     }
    130     return $image_magick_ok;
    131    
    132 }
     106        $image_conversion_available = 0;
     107        $no_image_conversion_reason = "imagemagicknotinstalled";
     108    }
     109    }
     110    $self->{'image_conversion_available'} = $image_conversion_available;
     111    $self->{'no_image_conversion_reason'} = $no_image_conversion_reason;
     112
     113    if ($self->{'image_conversion_available'} == 0) {
     114    my $outhandle = $self->{'outhandle'};
     115    &gsprintf($outhandle, "ImageConverter: {ImageConverter.noconversionavailable} ({ImageConverter.".$self->{'no_image_conversion_reason'}."})\n");
     116    }
     117}
     118   
    133119
    134120# convert image to new type if converttotype is set
     
    141127    my ($filename_full_path, $filename_no_path, $doc_obj, $section) = @_;
    142128
     129    # check image magick status
     130    return 0 if $self->{'image_conversion_available'} == 0;
    143131    # check the filenames
    144132    return 0 if ($filename_no_path eq "" || !-f $filename_full_path);
Note: See TracChangeset for help on using the changeset viewer.