Changeset 25778 for main/trunk/greenstone2
- Timestamp:
- 2012-06-07T16:24:10+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/plugins/ImageConverter.pm
r24763 r25778 248 248 249 249 # 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) 251 251 = &identify($filename_full_path, $outhandle, $verbosity); 252 252 … … 262 262 $doc_obj->add_metadata ($section, "ImageWidth", $image_width); 263 263 $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); 265 265 266 266 if ((defined $self->{'MaxImageWidth'}) … … 467 467 # Read the size 468 468 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 470 473 $size = $1; 471 474 } 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 473 481 $size = 1024 * $1; 474 482 if (defined($2)) { … … 478 486 } 479 487 } 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 481 494 $size = 1024 * 1024 * $1; 482 495 if (defined($2)) { … … 485 498 $size = int($size); 486 499 } 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 489 505 # Deals with file sizes on Linux of type "3.4e+02kb" where e+02 is 1*10^2. 490 506 # 3.4e+02 therefore evaluates to 3.4 x 1 x 10^2 = 340kb. 491 507 # Programming languages including Perl know how that 3.4e+02 is a number, 492 508 # 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 494 511 #if we did $size = $1; $size would be merely the string "3.4e+02" 495 512 $size = int($size); # truncate size 496 513 } 497 print $outhandle "file: $image:\t $type, $width, $height, $size \n"514 print $outhandle "file: $image:\t $type, $width, $height, $size, $size_str\n" 498 515 if ($verbosity > 2); 499 516 500 517 # Return the specs 501 return ($type, $width, $height, $size );518 return ($type, $width, $height, $size, $size_str); 502 519 } 503 520
Note:
See TracChangeset
for help on using the changeset viewer.