Changeset 3137
- Timestamp:
- 2002-06-07T12:32:11+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/ImagePlug.pm
r2882 r3137 58 58 " 59 59 } 60 60 61 61 62 sub new { … … 84 85 } 85 86 87 86 88 sub get_default_process_exp { 87 89 my $self = shift (@_); … … 118 120 } 119 121 120 121 122 # Convert the image to a new type (if required). 122 123 my $converttotype = $self->{'converttotype'}; … … 139 140 } 140 141 142 # Add the image metadata 143 $doc_obj->add_metadata ($section, "Image", "$file"); 144 my ($image_type, $image_width, $image_height, $image_size) 145 = &identify($filename, $outhandle, $verbosity); 146 147 $doc_obj->add_metadata ($section, "ImageType", $image_type); 148 $doc_obj->add_metadata ($section, "ImageWidth", $image_width); 149 $doc_obj->add_metadata ($section, "ImageHeight", $image_height); 150 $doc_obj->add_metadata ($section, "ImageSize", $image_size); 151 152 # Add the image as an associated file 153 $doc_obj->associate_file($filename,$file,"image/$type",$section); 141 154 142 155 # Make the thumbnail image 143 my $thumbnailsize = $self->{'thumbnailsize'} 156 my $thumbnailsize = $self->{'thumbnailsize'} || 100; 144 157 my $thumbnailtype = $self->{'thumbnailtype'} || 'gif'; 145 146 my $thumbnailfilename = &util::get_tmp_filename() . ".$thumbnailtype"; 147 $self->{'tmp_filename2'} = $thumbnailfilename; 158 my $thumbnailfile = &util::get_tmp_filename() . ".$thumbnailtype"; 159 $self->{'tmp_filename2'} = $thumbnailfile; 148 160 149 161 # Generate the thumbnail with convert 150 162 my $command = "convert -verbose -geometry $thumbnailsize" 151 . "x$thumbnailsize $filename $thumbnailfile name";163 . "x$thumbnailsize $filename $thumbnailfile"; 152 164 print $outhandle "$command\n" if ($verbosity > 2); 153 165 my $result = ''; … … 156 168 157 169 # Add the thumbnail as an associated file ... 158 if (-e "$thumbnailfile name") {159 $doc_obj->associate_file("$thumbnailfile name", "thumbnail.$thumbnailtype",170 if (-e "$thumbnailfile") { 171 $doc_obj->associate_file("$thumbnailfile", "thumbnail.$thumbnailtype", 160 172 "image/$thumbnailtype",$section); 161 173 $doc_obj->add_metadata ($section, "ThumbType", $thumbnailtype); … … 163 175 } 164 176 165 166 # Extract Image metadata from convert output 167 if ($result =~ m/([0-9]+)x([0-9]+)=>([0-9]+)x([0-9]+)/) { 168 $doc_obj->add_metadata ($section, "ImageWidth", $1); 169 $doc_obj->add_metadata ($section, "ImageHeight", $2); 170 $doc_obj->add_metadata ($section, "ThumbWidth", $3); 171 $doc_obj->add_metadata ($section, "ThumbHeight", $4); 172 } 173 174 my $size = "unknown"; 175 if ($result =~ m/^[^\n]* ([0-9]+)b/) { 176 $size = $1; 177 } elsif ($result =~ m/^[^\n]* ([0-9]+)kb/) { 178 $size = 1024 * $1; 179 } 180 181 if ($result =~ m/^[^\n]*JPE?G/i) { 182 $type = "jpeg"; 183 } elsif ($result =~ m/^[^\n]*GIF/i) { 184 $type = "gif"; 185 } elsif ($result =~ m/^[^\n]*PNG/i) { 186 $type = "png"; 187 } elsif ($result =~ m/^[^\n]*TIF?F/i) { 188 $type = "tiff"; 189 } elsif ($result =~ m/^[^\n]*BMP/i) { 190 $type = "bmp"; 191 } elsif ($result =~ m/^[^\n]*XBM?F/i) { 192 $type = "xbm"; 193 } 194 195 $doc_obj->add_metadata ($section, "ImageType", $type); 196 $doc_obj->add_metadata ($section, "Image", "$file"); 197 $doc_obj->add_metadata ($section, "ImageSize", $size); 198 199 # Add the image as an associated file ... 200 $doc_obj->associate_file($filename,$file,"image/$type",$section); 201 177 # Extract Thumnail metadata from convert output 178 if ($result =~ m/[0-9]+x[0-9]+=>([0-9]+)x([0-9]+)/) { 179 $doc_obj->add_metadata ($section, "ThumbWidth", $1); 180 $doc_obj->add_metadata ($section, "ThumbHeight", $2); 181 } 202 182 203 183 # Make a screen-sized version of the picture if requested 204 184 if ($self->{'screenviewsize'}) { 185 186 # To do: if the actual image smaller than the screenview size, 187 # we should use the original ! 205 188 206 189 my $screenviewsize = $self->{'screenviewsize'}; … … 235 218 236 219 return $type; 237 238 220 } 221 222 223 # Discover the characteristics of an image file with the ImageMagick 224 # "identify" command. 225 226 sub identify { 227 my ($image, $outhandle, $verbosity) = @_; 228 229 # Use the ImageMagick "identify" command to get the file specs 230 my $command = "identify $image 2>&1"; 231 print $outhandle "$command\n" if ($verbosity > 2); 232 my $result = ''; 233 $result = `$command`; 234 print $outhandle "$result\n" if ($verbosity > 3); 235 236 # Read the type, width, and height 237 my $type = 'unknown'; 238 my $width = 'unknown'; 239 my $height = 'unknown'; 240 241 if ($result =~ /^$image (\w+) (\d+)x(\d+)/) { 242 $type = $1; 243 $width = $2; 244 $height = $3; 245 } 246 247 # Read the size 248 my $size = "unknown"; 249 if ($result =~ m/^.* ([0-9]+)b/) { 250 $size = $1; 251 } elsif ($result =~ m/^.* ([0-9]+)kb/) { 252 $size = 1024 * $1; 253 } 254 255 print $outhandle "file: $image:\t $type, $width, $height, $size\n" 256 if ($verbosity > 2); 257 258 # Return the specs 259 return ($type, $width, $height, $size); 239 260 } 240 261 … … 334 355 335 356 1; 336 337 338 339 340 341 342 343 344 345 346
Note:
See TracChangeset
for help on using the changeset viewer.