[1733] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # ImagePlug.pm -- simple text plugin
|
---|
| 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
| 26 | package ImagePlug;
|
---|
| 27 |
|
---|
| 28 | use BasPlug;
|
---|
| 29 |
|
---|
[10254] | 30 | use strict;
|
---|
| 31 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 32 |
|
---|
[1733] | 33 | sub BEGIN {
|
---|
[10254] | 34 | @ImagePlug::ISA = ('BasPlug');
|
---|
[1733] | 35 | }
|
---|
| 36 |
|
---|
[4744] | 37 | my $arguments =
|
---|
| 38 | [ { 'name' => "process_exp",
|
---|
[4873] | 39 | 'desc' => "{BasPlug.process_exp}",
|
---|
[6408] | 40 | 'type' => "regexp",
|
---|
[4744] | 41 | 'deft' => &get_default_process_exp(),
|
---|
| 42 | 'reqd' => "no" },
|
---|
| 43 | { 'name' => "noscaleup",
|
---|
[4873] | 44 | 'desc' => "{ImagePlug.noscaleup}",
|
---|
[4744] | 45 | 'type' => "flag",
|
---|
| 46 | 'reqd' => "no" },
|
---|
| 47 | { 'name' => "thumbnailsize",
|
---|
[4873] | 48 | 'desc' => "{ImagePlug.thumbnailsize}",
|
---|
[4744] | 49 | 'type' => "int",
|
---|
| 50 | 'deft' => "100",
|
---|
[10218] | 51 | 'range' => "1,",
|
---|
[4744] | 52 | 'reqd' => "no" },
|
---|
| 53 | { 'name' => "thumbnailtype",
|
---|
[4873] | 54 | 'desc' => "{ImagePlug.thumbnailtype}",
|
---|
[4744] | 55 | 'type' => "string",
|
---|
| 56 | 'deft' => "gif",
|
---|
| 57 | 'reqd' => "no" },
|
---|
| 58 | { 'name' => "screenviewsize",
|
---|
[4873] | 59 | 'desc' => "{ImagePlug.screenviewsize}",
|
---|
[4744] | 60 | 'type' => "int",
|
---|
| 61 | 'deft' => "0",
|
---|
[10218] | 62 | 'range' => "1,",
|
---|
[4744] | 63 | 'reqd' => "no" },
|
---|
| 64 | { 'name' => "screenviewtype",
|
---|
[4873] | 65 | 'desc' => "{ImagePlug.screenviewtype}",
|
---|
[4744] | 66 | 'type' => "string",
|
---|
| 67 | 'deft' => "jpg",
|
---|
| 68 | 'reqd' => "no" },
|
---|
| 69 | { 'name' => "converttotype",
|
---|
[4873] | 70 | 'desc' => "{ImagePlug.converttotype}",
|
---|
[4744] | 71 | 'type' => "string",
|
---|
| 72 | 'deft' => "",
|
---|
| 73 | 'reqd' => "no" },
|
---|
| 74 | { 'name' => "minimumsize",
|
---|
[4873] | 75 | 'desc' => "{ImagePlug.minimumsize}",
|
---|
[4744] | 76 | 'type' => "int",
|
---|
| 77 | 'deft' => "100",
|
---|
[10218] | 78 | 'range' => "1,",
|
---|
[4744] | 79 | 'reqd' => "no" } ];
|
---|
[1758] | 80 |
|
---|
[3540] | 81 | my $options = { 'name' => "ImagePlug",
|
---|
[5680] | 82 | 'desc' => "{ImagePlug.desc}",
|
---|
[6408] | 83 | 'abstract' => "no",
|
---|
[3540] | 84 | 'inherits' => "yes",
|
---|
| 85 | 'args' => $arguments };
|
---|
| 86 |
|
---|
| 87 |
|
---|
[1744] | 88 |
|
---|
[1733] | 89 | sub new {
|
---|
[10218] | 90 | my ($class) = shift (@_);
|
---|
| 91 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 92 | push(@$pluginlist, $class);
|
---|
[4724] | 93 |
|
---|
[10218] | 94 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
| 95 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
[2230] | 96 |
|
---|
[12169] | 97 | my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[1744] | 98 |
|
---|
[9574] | 99 | # Check that ImageMagick is installed and available on the path (except for Windows 95/98)
|
---|
| 100 | if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
|
---|
| 101 | my $result = `identify 2>&1`;
|
---|
| 102 | if ($? == -1 || $? == 256) { # Linux and Windows return different values for "program not found"
|
---|
| 103 | $self->{'imagemagick_not_installed'} = 1;
|
---|
| 104 | }
|
---|
[8145] | 105 | }
|
---|
| 106 |
|
---|
[13243] | 107 |
|
---|
[1733] | 108 | return bless $self, $class;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | sub get_default_process_exp {
|
---|
| 112 | my $self = shift (@_);
|
---|
| 113 |
|
---|
[1758] | 114 | return q^(?i)(\.jpe?g|\.gif|\.png|\.bmp|\.xbm|\.tif?f)$^;
|
---|
[1733] | 115 | }
|
---|
| 116 |
|
---|
[9067] | 117 | # this makes no sense for images
|
---|
| 118 | sub block_cover_image
|
---|
| 119 | {
|
---|
| 120 | my $self =shift (@_);
|
---|
| 121 | my ($filename) = @_;
|
---|
[2230] | 122 |
|
---|
[9067] | 123 | return;
|
---|
| 124 | }
|
---|
[2230] | 125 | # Create the thumbnail and screenview images, and discover the Image's
|
---|
| 126 | # size, width, and height using the convert utility.
|
---|
| 127 |
|
---|
[1733] | 128 | sub run_convert {
|
---|
| 129 | my $self = shift (@_);
|
---|
[2230] | 130 | my $filename = shift (@_); # filename with full path
|
---|
| 131 | my $file = shift (@_); # filename without path
|
---|
[1733] | 132 | my $doc_obj = shift (@_);
|
---|
[1744] | 133 | my $section = $doc_obj->get_top_section();
|
---|
[2230] | 134 |
|
---|
| 135 | my $verbosity = $self->{'verbosity'};
|
---|
| 136 | my $outhandle = $self->{'outhandle'};
|
---|
[1733] | 137 |
|
---|
[2230] | 138 | # check the filename is okay
|
---|
| 139 | return 0 if ($file eq "" || $filename eq "");
|
---|
| 140 |
|
---|
[3307] | 141 | # Code now extended to quote filenames in 'convert' commnads
|
---|
| 142 | # Allows spaces in filenames, but note needs spaces to be escaped in URL as well
|
---|
| 143 | # if ($filename =~ m/ /) {
|
---|
| 144 | # print $outhandle "ImagePlug: \"$filename\" contains a space. choking.\n";
|
---|
| 145 | # return undef;
|
---|
| 146 | # }
|
---|
[1744] | 147 |
|
---|
[1758] | 148 | my $minimumsize = $self->{'minimumsize'};
|
---|
[2230] | 149 | if (defined $minimumsize && (-s $filename < $minimumsize)) {
|
---|
| 150 | print $outhandle "ImagePlug: \"$filename\" too small, skipping\n"
|
---|
| 151 | if ($verbosity > 1);
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[4724] | 154 |
|
---|
[2230] | 155 | # Convert the image to a new type (if required).
|
---|
[1744] | 156 | my $converttotype = $self->{'converttotype'};
|
---|
[2230] | 157 | my $originalfilename = ""; # only set if we do a conversion
|
---|
[1733] | 158 | my $type = "unknown";
|
---|
[1758] | 159 |
|
---|
[13879] | 160 | if ($converttotype ne "" && $filename !~ m/$converttotype$/) {
|
---|
[1744] | 161 | $originalfilename = $filename;
|
---|
[2230] | 162 | $filename = &util::get_tmp_filename() . ".$converttotype";
|
---|
[1744] | 163 | $self->{'tmp_filename'} = $filename;
|
---|
[2230] | 164 |
|
---|
[3307] | 165 | my $command = "convert -interlace plane -verbose \"$originalfilename\" \"$filename\"";
|
---|
[2230] | 166 | print $outhandle "$command\n" if ($verbosity > 2);
|
---|
| 167 | my $result = '';
|
---|
[1744] | 168 | $result = `$command`;
|
---|
[4724] | 169 | print $outhandle "RESULT = $result\n" if ($verbosity > 2);
|
---|
[2230] | 170 |
|
---|
[1744] | 171 | $type = $converttotype;
|
---|
[13879] | 172 | $file =~ s/\..*$/\.$type/;
|
---|
[1733] | 173 | }
|
---|
[1744] | 174 |
|
---|
[4724] | 175 |
|
---|
[3137] | 176 | # Add the image metadata
|
---|
[3307] | 177 | my $url = $file;
|
---|
[13542] | 178 |
|
---|
| 179 | ##not know why it is required at the first place, it seems all works fine without it, so I comment it out
|
---|
| 180 | ##$url =~ s/ /%20/g;
|
---|
[3307] | 181 |
|
---|
| 182 | $doc_obj->add_metadata ($section, "Image", $url);
|
---|
[3517] | 183 |
|
---|
| 184 | # Also want to set filename as 'Source' metadata to be
|
---|
| 185 | # consistent with other plugins
|
---|
| 186 | $doc_obj->add_metadata ($section, "Source", $url);
|
---|
| 187 |
|
---|
[3137] | 188 | my ($image_type, $image_width, $image_height, $image_size)
|
---|
| 189 | = &identify($filename, $outhandle, $verbosity);
|
---|
[2230] | 190 |
|
---|
[8121] | 191 | if ($image_type ne " ") {
|
---|
| 192 | $type = $image_type;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | $doc_obj->add_metadata ($section, "FileFormat", $type);
|
---|
[8166] | 196 | $doc_obj->add_metadata ($section, "FileSize", $image_size);
|
---|
[8121] | 197 |
|
---|
[3137] | 198 | $doc_obj->add_metadata ($section, "ImageType", $image_type);
|
---|
| 199 | $doc_obj->add_metadata ($section, "ImageWidth", $image_width);
|
---|
| 200 | $doc_obj->add_metadata ($section, "ImageHeight", $image_height);
|
---|
| 201 | $doc_obj->add_metadata ($section, "ImageSize", $image_size);
|
---|
[14117] | 202 | $doc_obj->add_metadata ($section, "NoText", "1");
|
---|
[3137] | 203 |
|
---|
[4724] | 204 | $doc_obj->add_metadata ($section, "srclink",
|
---|
[11834] | 205 | "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Image]\">");
|
---|
[4724] | 206 | $doc_obj->add_metadata ($section, "/srclink", "</a>");
|
---|
| 207 |
|
---|
[11834] | 208 | $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Image]\" width=100>");
|
---|
[4724] | 209 |
|
---|
| 210 |
|
---|
[3137] | 211 | # Add the image as an associated file
|
---|
| 212 | $doc_obj->associate_file($filename,$file,"image/$type",$section);
|
---|
| 213 |
|
---|
[4724] | 214 |
|
---|
[2230] | 215 | # Make the thumbnail image
|
---|
[3137] | 216 | my $thumbnailsize = $self->{'thumbnailsize'} || 100;
|
---|
[2230] | 217 | my $thumbnailtype = $self->{'thumbnailtype'} || 'gif';
|
---|
[4724] | 218 |
|
---|
[3137] | 219 | my $thumbnailfile = &util::get_tmp_filename() . ".$thumbnailtype";
|
---|
| 220 | $self->{'tmp_filename2'} = $thumbnailfile;
|
---|
[1733] | 221 |
|
---|
[2230] | 222 | # Generate the thumbnail with convert
|
---|
[3307] | 223 | my $command = "convert -interlace plane -verbose -geometry $thumbnailsize"
|
---|
| 224 | . "x$thumbnailsize \"$filename\" \"$thumbnailfile\"";
|
---|
[4724] | 225 | print $outhandle "THUMBNAIL: $command\n" if ($verbosity > 2);
|
---|
[2230] | 226 | my $result = '';
|
---|
[2882] | 227 | $result = `$command 2>&1` ;
|
---|
[4724] | 228 | print $outhandle "THUMB RESULT: $result\n" if ($verbosity > 2);
|
---|
[2230] | 229 |
|
---|
| 230 | # Add the thumbnail as an associated file ...
|
---|
[3137] | 231 | if (-e "$thumbnailfile") {
|
---|
| 232 | $doc_obj->associate_file("$thumbnailfile", "thumbnail.$thumbnailtype",
|
---|
[2230] | 233 | "image/$thumbnailtype",$section);
|
---|
| 234 | $doc_obj->add_metadata ($section, "ThumbType", $thumbnailtype);
|
---|
| 235 | $doc_obj->add_metadata ($section, "Thumb", "thumbnail.$thumbnailtype");
|
---|
[4724] | 236 |
|
---|
[11834] | 237 | $doc_obj->add_metadata ($section, "thumbicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Thumb]\" width=[ThumbWidth] height=[ThumbHeight]>");
|
---|
[2230] | 238 | }
|
---|
| 239 |
|
---|
[3137] | 240 | # Extract Thumnail metadata from convert output
|
---|
| 241 | if ($result =~ m/[0-9]+x[0-9]+=>([0-9]+)x([0-9]+)/) {
|
---|
| 242 | $doc_obj->add_metadata ($section, "ThumbWidth", $1);
|
---|
| 243 | $doc_obj->add_metadata ($section, "ThumbHeight", $2);
|
---|
[1733] | 244 | }
|
---|
[1758] | 245 |
|
---|
[2230] | 246 | # Make a screen-sized version of the picture if requested
|
---|
| 247 | if ($self->{'screenviewsize'}) {
|
---|
| 248 |
|
---|
[3137] | 249 | # To do: if the actual image smaller than the screenview size,
|
---|
| 250 | # we should use the original !
|
---|
| 251 |
|
---|
[2230] | 252 | my $screenviewsize = $self->{'screenviewsize'};
|
---|
| 253 | my $screenviewtype = $self->{'screenviewtype'} || 'jpeg';
|
---|
| 254 | my $screenviewfilename = &util::get_tmp_filename() . ".$screenviewtype";
|
---|
| 255 | $self->{'tmp_filename3'} = $screenviewfilename;
|
---|
| 256 |
|
---|
| 257 | # make the screenview image
|
---|
[3307] | 258 | my $command = "convert -interlace plane -verbose -geometry $screenviewsize"
|
---|
| 259 | . "x$screenviewsize \"$filename\" \"$screenviewfilename\"";
|
---|
[2230] | 260 | print $outhandle "$command\n" if ($verbosity > 2);
|
---|
| 261 | my $result = "";
|
---|
[2882] | 262 | $result = `$command 2>&1` ;
|
---|
[2230] | 263 | print $outhandle "$result\n" if ($verbosity > 3);
|
---|
| 264 |
|
---|
| 265 | # get screenview dimensions, size and type
|
---|
| 266 | if ($result =~ m/[0-9]+x[0-9]+=>([0-9]+)x([0-9]+)/) {
|
---|
| 267 | $doc_obj->add_metadata ($section, "ScreenWidth", $1);
|
---|
| 268 | $doc_obj->add_metadata ($section, "ScreenHeight", $2);
|
---|
| 269 | }
|
---|
[5078] | 270 | else {
|
---|
| 271 | $doc_obj->add_metadata ($section, "ScreenWidth", $image_width);
|
---|
| 272 | $doc_obj->add_metadata ($section, "ScreenHeight", $image_height);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[2230] | 275 | #add the screenview as an associated file ...
|
---|
| 276 | if (-e "$screenviewfilename") {
|
---|
| 277 | $doc_obj->associate_file("$screenviewfilename", "screenview.$screenviewtype",
|
---|
| 278 | "image/$screenviewtype",$section);
|
---|
| 279 | $doc_obj->add_metadata ($section, "ScreenType", $screenviewtype);
|
---|
| 280 | $doc_obj->add_metadata ($section, "Screen", "screenview.$screenviewtype");
|
---|
[4724] | 281 |
|
---|
[11834] | 282 | $doc_obj->add_metadata ($section, "screenicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Screen]\" width=[ScreenWidth] height=[ScreenHeight]>");
|
---|
[2230] | 283 | } else {
|
---|
| 284 | print $outhandle "ImagePlug: couldn't find \"$screenviewfilename\"\n";
|
---|
| 285 | }
|
---|
| 286 | }
|
---|
| 287 |
|
---|
[1733] | 288 | return $type;
|
---|
[4724] | 289 |
|
---|
| 290 |
|
---|
[3137] | 291 | }
|
---|
[2230] | 292 |
|
---|
| 293 |
|
---|
[4724] | 294 |
|
---|
[3137] | 295 | # Discover the characteristics of an image file with the ImageMagick
|
---|
| 296 | # "identify" command.
|
---|
| 297 |
|
---|
| 298 | sub identify {
|
---|
| 299 | my ($image, $outhandle, $verbosity) = @_;
|
---|
| 300 |
|
---|
| 301 | # Use the ImageMagick "identify" command to get the file specs
|
---|
[5845] | 302 | my $command = "identify \"$image\" 2>&1";
|
---|
[3137] | 303 | print $outhandle "$command\n" if ($verbosity > 2);
|
---|
| 304 | my $result = '';
|
---|
| 305 | $result = `$command`;
|
---|
| 306 | print $outhandle "$result\n" if ($verbosity > 3);
|
---|
| 307 |
|
---|
| 308 | # Read the type, width, and height
|
---|
| 309 | my $type = 'unknown';
|
---|
| 310 | my $width = 'unknown';
|
---|
| 311 | my $height = 'unknown';
|
---|
| 312 |
|
---|
[4790] | 313 | my $image_safe = quotemeta $image;
|
---|
| 314 | if ($result =~ /^$image_safe (\w+) (\d+)x(\d+)/) {
|
---|
[3137] | 315 | $type = $1;
|
---|
| 316 | $width = $2;
|
---|
| 317 | $height = $3;
|
---|
| 318 | }
|
---|
[5103] | 319 |
|
---|
[3137] | 320 | # Read the size
|
---|
| 321 | my $size = "unknown";
|
---|
| 322 | if ($result =~ m/^.* ([0-9]+)b/) {
|
---|
| 323 | $size = $1;
|
---|
[5103] | 324 | }
|
---|
[5845] | 325 | elsif ($result =~ m/^.* ([0-9]+)(\.([0-9]+))?kb?/) {
|
---|
[3137] | 326 | $size = 1024 * $1;
|
---|
[5103] | 327 | if (defined($2)) {
|
---|
| 328 | $size = $size + (1024 * $2);
|
---|
| 329 | # Truncate size (it isn't going to be very accurate anyway)
|
---|
| 330 | $size = int($size);
|
---|
| 331 | }
|
---|
[3137] | 332 | }
|
---|
| 333 |
|
---|
| 334 | print $outhandle "file: $image:\t $type, $width, $height, $size\n"
|
---|
| 335 | if ($verbosity > 2);
|
---|
| 336 |
|
---|
| 337 | # Return the specs
|
---|
| 338 | return ($type, $width, $height, $size);
|
---|
[1733] | 339 | }
|
---|
| 340 |
|
---|
| 341 |
|
---|
[11090] | 342 | # The ImagePlug read() function.
|
---|
[1733] | 343 | # ImagePlug overrides read() because there is no need to read the actual
|
---|
| 344 | # text of the file in, because the contents of the file is not text...
|
---|
| 345 | #
|
---|
| 346 | # Return number of files processed, undef if can't process
|
---|
| 347 | # Note that $base_dir might be "" and that $file might
|
---|
| 348 | # include directories
|
---|
| 349 |
|
---|
| 350 | sub read {
|
---|
| 351 | my $self = shift (@_);
|
---|
[9853] | 352 | my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
|
---|
[1733] | 353 |
|
---|
[2230] | 354 | my $outhandle = $self->{'outhandle'};
|
---|
| 355 |
|
---|
[11090] | 356 | #check process and block exps, smart block, etc
|
---|
| 357 | my ($block_status,$filename) = $self->read_block(@_);
|
---|
| 358 | return $block_status if ((!defined $block_status) || ($block_status==0));
|
---|
[6332] | 359 |
|
---|
| 360 | print STDERR "<Processing n='$file' p='ImagePlug'>\n" if ($gli);
|
---|
[9960] | 361 | print $outhandle "ImagePlug processing $file\n"
|
---|
[1758] | 362 | if $self->{'verbosity'} > 1;
|
---|
| 363 |
|
---|
[9585] | 364 | # None of this works very well on Windows 95/98...
|
---|
| 365 | if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) {
|
---|
| 366 | if ($gli) {
|
---|
| 367 | print STDERR "<ProcessingError n='$file' r='Windows 95/98 not supported'>\n";
|
---|
| 368 | }
|
---|
[9703] | 369 | print $outhandle "ImagePlug: Windows 95/98 not supported\n";
|
---|
[9585] | 370 | return -1;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | # None of this is going to work very well without ImageMagick...
|
---|
| 374 | if ($self->{'imagemagick_not_installed'}) {
|
---|
| 375 | if ($gli) {
|
---|
| 376 | print STDERR "<ProcessingError n='$file' r='ImageMagick not installed'>\n";
|
---|
| 377 | }
|
---|
[9703] | 378 | print $outhandle "ImagePlug: ImageMagick not installed\n";
|
---|
[9585] | 379 | return -1;
|
---|
| 380 | }
|
---|
| 381 |
|
---|
[2230] | 382 | #if there's a leading directory name, eat it...
|
---|
| 383 | $file =~ s/^.*[\/\\]//;
|
---|
[1733] | 384 |
|
---|
| 385 | # create a new document
|
---|
| 386 | my $doc_obj = new doc ($filename, "indexed_doc");
|
---|
[12270] | 387 | $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});
|
---|
[7508] | 388 | $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
|
---|
[2327] | 389 |
|
---|
[1733] | 390 | #run convert to get the thumbnail and extract size and type info
|
---|
[1758] | 391 | my $result = run_convert($self, $filename, $file, $doc_obj);
|
---|
[1744] | 392 |
|
---|
[1758] | 393 | if (!defined $result)
|
---|
[1744] | 394 | {
|
---|
[9585] | 395 | if ($gli) {
|
---|
| 396 | print STDERR "<ProcessingError n='$file'>\n";
|
---|
| 397 | }
|
---|
[9703] | 398 | print $outhandle "ImagePlug: couldn't process \"$filename\"\n";
|
---|
[7362] | 399 | return -1; # error during processing
|
---|
[1733] | 400 | }
|
---|
| 401 |
|
---|
[13243] | 402 |
|
---|
[13269] | 403 | #create an empty text string so we don't break downstream plugins
|
---|
| 404 | my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}",1);
|
---|
| 405 |
|
---|
[1733] | 406 | # include any metadata passed in from previous plugins
|
---|
| 407 | # note that this metadata is associated with the top level section
|
---|
[1744] | 408 | my $section = $doc_obj->get_top_section();
|
---|
[1733] | 409 | $self->extra_metadata ($doc_obj, $section, $metadata);
|
---|
| 410 |
|
---|
| 411 | # do plugin specific processing of doc_obj
|
---|
[9585] | 412 | unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
|
---|
| 413 | print STDERR "<ProcessingError n='$file'>\n" if ($gli);
|
---|
| 414 | return -1;
|
---|
| 415 | }
|
---|
[1733] | 416 |
|
---|
| 417 | # do any automatic metadata extraction
|
---|
| 418 | $self->auto_extract_metadata ($doc_obj);
|
---|
| 419 |
|
---|
[8350] | 420 | # if we haven't found any Title so far, assign one
|
---|
| 421 | # this was shifted to here from inside read()
|
---|
| 422 | $self->title_fallback($doc_obj,$section,$file);
|
---|
[1733] | 423 | # add an OID
|
---|
| 424 | $doc_obj->set_OID();
|
---|
[13243] | 425 | $doc_obj->add_utf8_text($section, $text);
|
---|
[1733] | 426 |
|
---|
| 427 | # process the document
|
---|
| 428 | $processor->process($doc_obj);
|
---|
| 429 |
|
---|
[2230] | 430 | # clean up temporary files - we do this here instead of in
|
---|
| 431 | # run_convert becuase associated files aren't actually copied
|
---|
| 432 | # until after process has been run.
|
---|
[1744] | 433 | if (defined $self->{'tmp_filename'} &&
|
---|
| 434 | -e $self->{'tmp_filename'}) {
|
---|
[2230] | 435 | &util::rm($self->{'tmp_filename'})
|
---|
[1733] | 436 | }
|
---|
[13243] | 437 |
|
---|
[1744] | 438 | if (defined $self->{'tmp_filename2'} &&
|
---|
| 439 | -e $self->{'tmp_filename2'}) {
|
---|
[2230] | 440 | &util::rm($self->{'tmp_filename2'})
|
---|
[1744] | 441 | }
|
---|
[2230] | 442 | if (defined $self->{'tmp_filename3'} &&
|
---|
| 443 | -e $self->{'tmp_filename3'}) {
|
---|
| 444 | &util::rm($self->{'tmp_filename3'})
|
---|
| 445 | }
|
---|
[1733] | 446 |
|
---|
[3307] | 447 | $self->{'num_processed'}++;
|
---|
| 448 |
|
---|
[2207] | 449 | return 1;
|
---|
[1733] | 450 | }
|
---|
| 451 |
|
---|
| 452 | # do plugin specific processing of doc_obj
|
---|
| 453 | sub process {
|
---|
| 454 | my $self = shift (@_);
|
---|
| 455 | my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
|
---|
| 456 | my $outhandle = $self->{'outhandle'};
|
---|
| 457 |
|
---|
| 458 | return 1;
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | 1;
|
---|
[4724] | 462 |
|
---|
| 463 |
|
---|
| 464 |
|
---|
| 465 |
|
---|
| 466 |
|
---|
| 467 |
|
---|
| 468 |
|
---|
| 469 |
|
---|
| 470 |
|
---|
| 471 |
|
---|
| 472 |
|
---|