Changeset 16825


Ignore:
Timestamp:
2008-08-15T15:33:36+12:00 (16 years ago)
Author:
davidb
Message:

Code for supporting cache merged back in with Katherine's restructured plugins

File:
1 edited

Legend:

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

    r16771 r16825  
    2626package ImageConverter;
    2727
    28 use PrintInfo;
     28use MediaConverter;
     29
    2930
    3031use strict;
     
    3435
    3536BEGIN {
    36     @ImageConverter::ISA = ('PrintInfo');
     37    @ImageConverter::ISA = ('MediaConverter');
    3738}
    3839
     
    111112    push(@{$hashArgOptLists->{"OptList"}},$options);
    112113
    113     my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
     114    my $self = new MediaConverter($pluginlist, $inputargs, $hashArgOptLists, 1);
     115
    114116
    115117    return bless $self, $class;
     
    163165    return 0 if ($filename_no_path eq "" || !-f $filename_full_path);
    164166
     167    if ($self->{'cache_generated_images'}) {
     168    $self->init_cache_for_file($filename_full_path);
     169    }
     170
    165171    my $verbosity = $self->{'verbosity'};
    166172    my $outhandle = $self->{'outhandle'};
     
    195201    #    $doc_obj->add_utf8_metadata($section, "Image", $utf8_filename_meta);
    196202
    197     my $result = $self->convert($filename_full_path, $converttotype, "", "");
    198     ($filename_full_path) = ($result =~ /=>(.*\.$converttotype)/);
     203    my ($result,$filename_full_path)
     204        = $self->convert($filename_full_path, $converttotype, "", "CONVERTTYPE");
    199205
    200206    $type = $converttotype;
     
    250256   
    251257    # Generate the thumbnail with convert
    252     my $result = $self->convert($original_file, $thumbnailtype, "-geometry $thumbnailsize" . "x$thumbnailsize", "THUMB");
    253     my ($thumbnailfile) = ($result =~ /=>(.*\.$thumbnailtype)/);
     258    my ($result,$thumbnailfile)
     259    = $self->convert($original_file, $thumbnailtype, "-geometry $thumbnailsize" . "x$thumbnailsize", "THUMB");
    254260   
    255261    # Add the thumbnail as an associated file ...
     
    288294   
    289295    # make the screenview image
    290     my $result = $self->convert($original_file, $screenviewtype, "-geometry $screenviewsize" . "x$screenviewsize", "SCREEN");
    291     my ($screenviewfilename) = ($result =~ /=>(.*\.$screenviewtype)/);
    292    
     296    my ($result,$screenviewfilename)
     297    = $self->convert($original_file, $screenviewtype, "-geometry $screenviewsize" . "x$screenviewsize", "SCREEN");   
    293298   
    294299    #add the screenview as an associated file ...
     
    323328    my $source_file_path = shift(@_);
    324329    my $target_file_type = shift(@_);
    325     my $convert_options = shift(@_) || "";
    326     my $convert_type = shift(@_) || "";
     330    my $convert_options  = shift(@_) || "";
     331    my $convert_id      = shift(@_) || "";
    327332
    328333    my $outhandle = $self->{'outhandle'};
    329334    my $verbosity = $self->{'verbosity'};
    330335
     336    my $source_file_no_path = &File::Basename::basename($source_file_path);
     337
    331338    # Determine the full name and path of the output file
    332     my $target_file_path = &util::get_tmp_filename($target_file_type);
    333     push(@{$self->{'tmp_file_paths'}}, $target_file_path);
     339    my $target_file_path;
     340    if ($self->{'cache_generated_images'}) {
     341    my $cached_image_dir = $self->{'cached_dir'};
     342    my $image_root = $self->{'cached_file_root'};
     343    $image_root .= "_$convert_id" if ($convert_id ne "");
     344    my $image_file = "$image_root.$target_file_type";
     345    $target_file_path = &util::filename_cat($cached_image_dir,$image_file);
     346    }
     347    else {
     348    $target_file_path = &util::get_tmp_filename($target_file_type);
     349    push(@{$self->{'tmp_file_paths'}}, $target_file_path);
     350
     351    # Output filename used to be parsed from result line:
     352    #   my ($ofilename) = ($result =~ m/=>(.*\.$target_file_type)/);
     353    # by the function that called 'convert'
     354    # but this is no longer needed, as output filename is now
     355    # explicitly passed back
     356
     357    }
    334358
    335359    # Generate and run the convert command
    336360    my $convert_command = "convert -interlace plane -verbose $convert_options \"$source_file_path\" \"$target_file_path\"";
    337     print $outhandle "$convert_type $convert_command\n" if ($verbosity > 2);
    338     my $result = `$convert_command 2>&1`;
    339     print $outhandle "$convert_type RESULT = $result\n" if ($verbosity > 2);
    340 
    341     return $result;
     361
     362    my $print_info = { 'message_prefix' => $convert_id,
     363               'message' => "Converting image $source_file_no_path to: $convert_id $target_file_type" };
     364 
     365    my ($regenerated,$result,$had_error)
     366    = $self->autorun_general_cmd($convert_command,$target_file_path,$print_info);
     367
     368    return ($result,$target_file_path);
    342369}
    343370
Note: See TracChangeset for help on using the changeset viewer.