Changeset 25778

Show
Ignore:
Timestamp:
07.06.2012 16:24:10 (7 years ago)
Author:
ak19
Message:

ex.ImageSize? and ex.FileSize? metadata were being set to the string unknown rather than the actual filesize returned by a call to imagick's identify. This was because the regex was too case-specific. Now ex.ImageSize? and ex.FileSize? are no longer the same: while ex.FileSize? remains the bytevalue that was calculated, ex.ImageSize? is now a display string.

Files:
1 modified

Legend:

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

    r24763 r25778  
    248248 
    249249    # use identify to get info about the (possibly converted) image 
    250     my ($image_type, $image_width, $image_height, $image_size)  
     250    my ($image_type, $image_width, $image_height, $image_size, $size_str)  
    251251    = &identify($filename_full_path, $outhandle, $verbosity); 
    252252 
     
    262262    $doc_obj->add_metadata ($section, "ImageWidth",  $image_width); 
    263263    $doc_obj->add_metadata ($section, "ImageHeight", $image_height); 
    264     $doc_obj->add_metadata ($section, "ImageSize",   $image_size); 
     264    $doc_obj->add_metadata ($section, "ImageSize",   $size_str); 
    265265 
    266266    if ((defined $self->{'MaxImageWidth'})  
     
    467467    # Read the size 
    468468    my $size = "unknown"; 
    469     if ($result =~ m/^.* ([0-9]+)b/) { 
     469    my $size_str="unknown"; 
     470 
     471    if ($result =~ m/^.* ([0-9]+)b/i) { 
     472    $size_str="$1B"; # display string 
    470473    $size = $1; 
    471474    } 
    472     elsif ($result =~ m/^.* ([0-9]+)(\.([0-9]+))?kb?/) { 
     475    elsif ($result =~ m/^.* ([0-9]+)(\.([0-9]+))?kb?/i) { 
     476    # display string stays about the same 
     477    $size_str="$1"; 
     478    $size_str.="$2" if defined $2; 
     479    $size_str.="KB"; 
     480 
    473481    $size = 1024 * $1; 
    474482    if (defined($2)) { 
     
    478486    } 
    479487    } 
    480     elsif ($result =~ m/^.* ([0-9]+)(\.([0-9]+))?mb?/) { 
     488    elsif ($result =~ m/^.* ([0-9]+)(\.([0-9]+))?mb?/i) { 
     489    # display string stays about the same 
     490    $size_str="$1"; 
     491    $size_str.="$2" if defined $2; 
     492    $size_str.="MB"; 
     493 
    481494    $size = 1024 * 1024 * $1; 
    482495        if (defined($2)) { 
     
    485498            $size = int($size); 
    486499        } 
    487      } 
    488     elsif ($result =~ m/^.* (([0-9]+)(\.([0-9]+))?e\+([0-9]+))(kb|b)?/) { 
     500    } 
     501    elsif ($result =~ m/^.* ((([0-9]+)(\.([0-9]+))?e\+([0-9]+))(kb|b)?)/i) { 
     502    # display string stays the same 
     503    $size_str="$1"; 
     504 
    489505    # Deals with file sizes on Linux of type "3.4e+02kb" where e+02 is 1*10^2. 
    490506    # 3.4e+02 therefore evaluates to 3.4 x 1 x 10^2 = 340kb. 
    491507    # Programming languages including Perl know how that 3.4e+02 is a number, 
    492508    # so we don't need to do any calculations. 
    493     $size = $1*1; # turn the string into a number by multiplying it by 1 
     509    # $2 is just the number without the kb/b at the end. 
     510    $size = $2*1; # turn the string into a number by multiplying it by 1 
    494511           #if we did $size = $1; $size would be merely the string "3.4e+02" 
    495512    $size = int($size); # truncate size 
    496513    } 
    497     print $outhandle "file: $image:\t $type, $width, $height, $size\n"  
     514    print $outhandle "file: $image:\t $type, $width, $height, $size, $size_str\n"  
    498515    if ($verbosity > 2); 
    499516 
    500517    # Return the specs 
    501     return ($type, $width, $height, $size); 
     518    return ($type, $width, $height, $size, $size_str); 
    502519} 
    503520