Index: trunk/gsdl/perllib/plugins/ImagePlug.pm
===================================================================
--- trunk/gsdl/perllib/plugins/ImagePlug.pm	(revision 2882)
+++ trunk/gsdl/perllib/plugins/ImagePlug.pm	(revision 3137)
@@ -58,4 +58,5 @@
 "
 }
+
 
 sub new {
@@ -84,4 +85,5 @@
 }
 
+
 sub get_default_process_exp {
     my $self = shift (@_);
@@ -118,5 +120,4 @@
     }
 
-
     # Convert the image to a new type (if required).
     my $converttotype = $self->{'converttotype'};
@@ -139,15 +140,26 @@
     }
     
+    # Add the image metadata
+    $doc_obj->add_metadata ($section, "Image", "$file");
+    my ($image_type, $image_width, $image_height, $image_size) 
+	= &identify($filename, $outhandle, $verbosity);
+
+    $doc_obj->add_metadata ($section, "ImageType",   $image_type);
+    $doc_obj->add_metadata ($section, "ImageWidth",  $image_width);
+    $doc_obj->add_metadata ($section, "ImageHeight", $image_height);
+    $doc_obj->add_metadata ($section, "ImageSize",   $image_size);
+
+    # Add the image as an associated file
+    $doc_obj->associate_file($filename,$file,"image/$type",$section);
 
     # Make the thumbnail image
-    my $thumbnailsize = $self->{'thumbnailsize'}  || 100;
+    my $thumbnailsize = $self->{'thumbnailsize'} || 100;
     my $thumbnailtype = $self->{'thumbnailtype'} || 'gif';
-	
-    my $thumbnailfilename = &util::get_tmp_filename() . ".$thumbnailtype";
-    $self->{'tmp_filename2'} = $thumbnailfilename;
+    my $thumbnailfile = &util::get_tmp_filename() . ".$thumbnailtype";
+    $self->{'tmp_filename2'} = $thumbnailfile;
 
     # Generate the thumbnail with convert
     my $command = "convert -verbose -geometry $thumbnailsize" 
-	. "x$thumbnailsize $filename $thumbnailfilename";
+	. "x$thumbnailsize $filename $thumbnailfile";
     print $outhandle "$command\n" if ($verbosity > 2);
     my $result = '';
@@ -156,6 +168,6 @@
 
     # Add the thumbnail as an associated file ...
-    if (-e "$thumbnailfilename") { 
-	$doc_obj->associate_file("$thumbnailfilename", "thumbnail.$thumbnailtype", 
+    if (-e "$thumbnailfile") { 
+	$doc_obj->associate_file("$thumbnailfile", "thumbnail.$thumbnailtype", 
 				 "image/$thumbnailtype",$section);
 	$doc_obj->add_metadata ($section, "ThumbType", $thumbnailtype);
@@ -163,44 +175,15 @@
     }
 
-
-    # Extract Image metadata from convert output
-    if ($result =~ m/([0-9]+)x([0-9]+)=>([0-9]+)x([0-9]+)/) {
-	$doc_obj->add_metadata ($section, "ImageWidth", $1);
-	$doc_obj->add_metadata ($section, "ImageHeight", $2);
-	$doc_obj->add_metadata ($section, "ThumbWidth", $3);
-	$doc_obj->add_metadata ($section, "ThumbHeight", $4);
-    }
-    
-    my $size = "unknown";
-    if ($result =~ m/^[^\n]* ([0-9]+)b/) {
-	$size = $1;
-    } elsif ($result =~ m/^[^\n]* ([0-9]+)kb/) {
-	$size = 1024 * $1;
-    }
-    
-    if ($result =~ m/^[^\n]*JPE?G/i) {
-	$type = "jpeg";
-    } elsif ($result =~ m/^[^\n]*GIF/i) {
-	$type = "gif";
-    } elsif ($result =~ m/^[^\n]*PNG/i) {
-	$type = "png";
-    } elsif ($result =~ m/^[^\n]*TIF?F/i) {
-	$type = "tiff";
-    } elsif ($result =~ m/^[^\n]*BMP/i) {
-	$type = "bmp";
-    } elsif ($result =~ m/^[^\n]*XBM?F/i) {
-	$type = "xbm";
-    }
-
-    $doc_obj->add_metadata ($section, "ImageType", $type);
-    $doc_obj->add_metadata ($section, "Image", "$file");
-    $doc_obj->add_metadata ($section, "ImageSize", $size);
-    
-    # Add the image as an associated file ...
-    $doc_obj->associate_file($filename,$file,"image/$type",$section);
-        
+    # Extract Thumnail metadata from convert output
+    if ($result =~ m/[0-9]+x[0-9]+=>([0-9]+)x([0-9]+)/) {
+	$doc_obj->add_metadata ($section, "ThumbWidth", $1);
+	$doc_obj->add_metadata ($section, "ThumbHeight", $2);
+    }
 
     # Make a screen-sized version of the picture if requested
     if ($self->{'screenviewsize'}) {
+
+	# To do: if the actual image smaller than the screenview size,
+	# we should use the original !
 
 	my $screenviewsize = $self->{'screenviewsize'};
@@ -235,6 +218,44 @@
 
     return $type;
-
-
+}
+
+
+# Discover the characteristics of an image file with the ImageMagick
+# "identify" command.
+
+sub identify { 
+    my ($image, $outhandle, $verbosity) = @_;
+
+    # Use the ImageMagick "identify" command to get the file specs
+    my $command = "identify $image 2>&1";
+    print $outhandle "$command\n" if ($verbosity > 2);
+    my $result = '';
+    $result = `$command`;
+    print $outhandle "$result\n" if ($verbosity > 3);
+
+    # Read the type, width, and height
+    my $type =   'unknown';
+    my $width =  'unknown';
+    my $height = 'unknown';
+
+    if ($result =~ /^$image (\w+) (\d+)x(\d+)/) {
+	$type = $1;
+	$width = $2;
+	$height = $3;
+    }
+	
+    # Read the size
+    my $size = "unknown";
+    if ($result =~ m/^.* ([0-9]+)b/) {
+	$size = $1;
+    } elsif ($result =~ m/^.* ([0-9]+)kb/) {
+	$size = 1024 * $1;
+    }
+
+    print $outhandle "file: $image:\t $type, $width, $height, $size\n" 
+	if ($verbosity > 2);
+
+    # Return the specs
+    return ($type, $width, $height, $size);
 }
 
@@ -334,13 +355,2 @@
 
 1;
-
-
-
-
-
-
-
-
-
-
-
