Changeset 1758


Ignore:
Timestamp:
2000-12-07T11:48:22+13:00 (23 years ago)
Author:
say1
Message:

added minimum image size and a few bug fixes

File:
1 edited

Legend:

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

    r1744 r1758  
    3333
    3434use strict;
     35
    3536sub print_general_usage {
    3637    my ($plugin_name) = @_;
     
    4142    print STDERR "   -thumbnailsize n Make thumbnails of size nxn\n";
    4243    print STDERR "   -convertto s     Convert main inage to (gif|png|jpg)\n";
     44    print STDERR "   -minimumsize n   Ignore images smaller than n bytes\n";
    4345    print STDERR "\n";
    4446}
     
    5557             q^converttotype/.*/^, \$self->{'converttotype'},
    5658             q^thumbnailsize/[0-9]*/100^, \$self->{'thumbnailsize'},
     59             q^minimumsize/[0-9]*/100^, \$self->{'minimumsize'},
    5760             "allow_extra_options")) {
    5861   
     
    6972    my $self = shift (@_);
    7073
    71     return q^(?i)(\.jpe?g|\.gif|\.png|\.bmp|\.tiff?)$^;
     74    return q^(?i)(\.jpe?g|\.gif|\.png|\.bmp|\.xbm|\.tif?f)$^;
    7275}
    7376
     
    8285    return "";
    8386    }
    84     if ($filename =~ m/thumbnail/) {
     87#    if ($filename =~ m/thumbnail/) {
     88#   return "";
     89#    }
     90#    if ($filename =~ m/converted/) {
     91#   return "";
     92#    }
     93    if ($filename =~ m/ /) {
     94    print STDERR "IamgePlug: \"$filename\" contains a space. choking.\n";
    8595    return "";
    8696    }
    87     if ($filename =~ m/converted/) {
    88     return "";
    89     }
    90     if ($filename =~ m/\..*\./) {
    91     return "";
    92     }
    93 
     97
     98    my $minimumsize = $self->{'minimumsize'};
    9499    my $thumbSize = $self->{'thumbnailsize'};
    95100    if ($thumbSize eq "") { $thumbSize = 100; };
     
    101106   
    102107    my $type = "unknown";
    103    
     108
     109    if (defined $minimumsize && (-s $filename < $minimumsize)) {
     110        print STDERR "ImagePlug: \"$filename\" too small, skipping\n"
     111        if $self->{'verbosity'} > 1;
     112    }
    104113    #see if we need to convert ...
    105     if ($converttotype ne "" && $filename =~ m/$converttotype$/)
    106     {
     114    if ($converttotype ne "" && $filename =~ m/$converttotype$/) {
    107115    $originalfilename = $filename;
    108116    $filename = &util::get_tmp_filename();
     
    137145        if $self->{'verbosity'} > 3;
    138146   
    139     if ($result =~ m/=>.* ([0-9]+)x([0-9]+)=>([0-9]+)x([0-9]+)/m) {
     147    if ($result =~ m/([0-9]+)x([0-9]+)=>([0-9]+)x([0-9]+)/) {
    140148    $doc_obj->add_metadata ($section, "ImageHeight", $1);
    141149    $doc_obj->add_metadata ($section, "ImageWidth", $2);
     
    167175    $type = "bmp";
    168176    }
    169    
     177    if ($result =~ m/^[^\n]*XBM?F/i) {
     178    $type = "xbm";
     179    }
     180
    170181    #if there's a leading directory name, eat it...
    171182    $file =~ s/^[^\/\\]*[\/\\]//;
     
    209220
    210221    my $filename = &util::filename_cat($base_dir, $file);
    211     print STDERR "ImagePlug: called on \"$filename\"\n"
    212         if $self->{'verbosity'} > 1;
    213222    return 0 if $self->{'block_exp'} ne "" && $filename =~ /$self->{'block_exp'}/;
    214223    if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
    215224    return undef;
    216225    }
    217     my $plugin_name = ref ($self);
     226    print STDERR "ImagePlug: called on \"$filename\"\n"
     227        if $self->{'verbosity'} > 1;
     228
    218229    $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up
    219230   
     
    222233   
    223234    #run convert to get the thumbnail and extract size and type info
    224     my $thumbnailfile = run_convert($self, $filename, $file, $doc_obj);
    225    
    226     if (!defined $thumbnailfile)
     235    my $result = run_convert($self, $filename, $file, $doc_obj);
     236   
     237    if (!defined $result)
    227238    {
    228239    print "ImagePlug: couldn't process \"$filename\"\n";
     
    261272    }
    262273
    263     return 1; # processed the file
     274    return $result; # processed the file
    264275}
    265276
Note: See TracChangeset for help on using the changeset viewer.