I am attempting to use Image::Magick to convert some mighty TIFFs (about 160MB each) into some more manageable scaled-down PNGs. Here is my code:
#!/usr/bin/perl use strict; use warnings; use Image::Magick; my $dir = shift @ARGV; # target directory, first argument. for(@ARGV) { # loop over file list print "processing file $_\n"; unless ( /\.tif?$/ ) { warn "$_ does not have a proper TIFF extension...skipping."; next; } my $image = Image::Magick->new; my $err; print "loading $_...\n"; $err = $image->read($_); warn $err if $err; print "scaling $_...\n"; $err = $image->Scale( geometry => '850x636' ); warn $err if $err; s{/.*/}{}; m/(.*?)\./; my $name = $dir . '/' . $1 . '.png'; print "writing $name...\n"; $err = $image->write( $name ); warn $err if $err; undef $image; }
The script is supposed to simply run through each TIFF file on the command line, scale it down, and output it as a PNG in the target directory. For reasons I can't figure out, it seems that the $image->write() method is writing two PNG files for each image. For example, img_0001.tif should produce img_0001.png. But instead, I get img_0001.png.0 and img_0001.png.1. The "0" images appear fine, and the "1" images are somewhat smaller (bytewise) and appear to have much higher compression. Here is my script's output and an example of the target directory after running the script on a CD with four images on it.
[friedo@localhost friedo]$ perl imgprep.pl /home/friedo/imgs/P-2004-00 +1/ /mnt/cdrom/* processing file /mnt/cdrom/img_0001.tif loading /mnt/cdrom/img_0001.tif... Exception 315: incorrect count for field "DateTime" (18, expecting 20) +; tag ignored. (/mnt/cdrom/img_0001.tif) at imgprep.pl line 22. scaling /mnt/cdrom/img_0001.tif... writing /home/friedo/imgs/P-2004-001//img_0001.png... processing file /mnt/cdrom/img_0002.tif loading /mnt/cdrom/img_0002.tif... Exception 315: incorrect count for field "DateTime" (18, expecting 20) +; tag ignored. (/mnt/cdrom/img_0002.tif) at imgprep.pl line 22. scaling /mnt/cdrom/img_0002.tif... writing /home/friedo/imgs/P-2004-001//img_0002.png... processing file /mnt/cdrom/img_0003.tif loading /mnt/cdrom/img_0003.tif... Exception 315: incorrect count for field "DateTime" (18, expecting 20) +; tag ignored. (/mnt/cdrom/img_0003.tif) at imgprep.pl line 22. scaling /mnt/cdrom/img_0003.tif... writing /home/friedo/imgs/P-2004-001//img_0003.png... processing file /mnt/cdrom/img_0004.tif loading /mnt/cdrom/img_0004.tif... Exception 315: incorrect count for field "DateTime" (18, expecting 20) +; tag ignored. (/mnt/cdrom/img_0004.tif) at imgprep.pl line 22. scaling /mnt/cdrom/img_0004.tif... writing /home/friedo/imgs/P-2004-001//img_0004.png... processing file /mnt/cdrom/scan log.txt file /mnt/cdrom/scan log.txt does not have a proper TIFF extension...s +kipping. at imgprep.pl line 14. [friedo@localhost P-2004-001]$ ls -al total 3564 drwxrwxr-x 2 friedo friedo 4096 Nov 11 03:22 . drwxrwxr-x 3 friedo friedo 4096 Nov 11 02:23 .. -rw-rw-r-- 1 friedo friedo 391734 Nov 11 03:17 img_0001.png.0 -rw-rw-r-- 1 friedo friedo 310422 Nov 11 03:17 img_0001.png.1 -rw-rw-r-- 1 friedo friedo 673542 Nov 11 03:19 img_0002.png.0 -rw-rw-r-- 1 friedo friedo 412338 Nov 11 03:19 img_0002.png.1 -rw-rw-r-- 1 friedo friedo 560091 Nov 11 03:21 img_0003.png.0 -rw-rw-r-- 1 friedo friedo 373808 Nov 11 03:21 img_0003.png.1 -rw-rw-r-- 1 friedo friedo 515991 Nov 11 03:22 img_0004.png.0 -rw-rw-r-- 1 friedo friedo 357368 Nov 11 03:22 img_0004.png.1
I appreciate any help. I'm sure it's something really stupid, but it's 3:30 in the morning and I'm stumped.
Thanks.
20041116 Edit by ysth: readmore tags
In reply to Image::Magick writing more files than I want. by friedo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |