[Originally posted by rkunesch on 2008-08-10 08:43:09-07]what is the perl way to do the following (extract a thumbnailimage of a file):
exiftool -b -thumbnailimage 'a.jpg' > win.jpg
the perlscript below shows the correct size ($len in bites) of the thumbnail, but extracts an image that differs in size and cannot be displayed in an browser.
use Image::ExifTool;
my $exifTool = new Image::ExifTool;
$exifTool->Options(Unknown => 1);
my $info = $exifTool->ImageInfo('a.jpg');
my $tag = 'ThumbnailImage';
my $val = $info->{$tag};
if (ref $val eq 'SCALAR') {
open (OUT, '>perl.jpg') or die "cannot open perl.jpg";
print OUT $$val;
close OUT;
if ($$val =~ /^Binary data/) {
$val = "($$val)";
} else {
my $len = length($$val);
$val = "(Binary data $len bytes)";
}
}
printf("%-32s : %s\n", $exifTool->GetDescription($tag), $val);
[Originally posted by exiftool on 2008-08-15 12:00:22-07]
This code works for me. I would suggest setting the "Binary => 1"
option when extracting the information. What exactly is
the size of the perl.jpg file that is written? Also, a hex dump
of the first few bytes might be helpful.
- Phil
[Originally posted by rkunesch on 2008-08-18 14:56:14-07]- corrected option to be "Binary => 1"
- thumbnail size of win.jpg => 12418 Bytes, size of perl.jpg => 12461 Bytes (exiftool 7.40 and Image::exif ver 7.30
- the htlDumps of the extracted ThumpnailImages show a differenz in the last column of line 0030:
-exiftool -htmldump win.jpg:
0000 ff d8 ff db 00 84 00 01 01 01 01 01 01 01 01 01
0010 01 01 01 01 02 02 03 02 02 02 02 02 04 03 03 02
0020 03 05 04 05 05 05 04 04 04 05 06 07 06 05 05 07
0030 06 04 04 06 09 06 07 08 08 08 08 08 05 06 09 0a
0040 09 08 0a 07 08 08 08 01 01 01 01 02 02 02 04 02
0050 02 04 08 05 04 05 08 08 08 08 08 08 08 08 08 08
0060 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
0070 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
... [snip 12176 bytes]
3010 f9 43 9c 0e 38 f5 af 0b 33 cc 21 87 a5 2a d3 d9
3020 7e a4 61 30 92 af 53 d9 43 e2 67 d1 ff 00 b5 cf
3030 ec 3c 7f 66 6f d9 d7 c3 1a 0f 8b 7c 47 a5 ea 9f
3040 10 ff 00 e1 22 37 97 33 d9 07 78 1f cd 87 6f 93
3050 1e e0 09 0a b1 a9 2c 40 c9 07 8e 95 f9 4d 37 85
3060 a7 40 42 de 5b bf 1d d5 85 61 94 42 58 ca 1f 58
3070 8b b2 6d ee 74 66 d4 be af 51 53 9e ad 25 fa 9f
3080 ff d9
-exiftool -htmldump perl.jpg:
0000 ff d8 ff db 00 84 00 01 01 01 01 01 01 01 01 01
0010 01 01 01 01 02 02 03 02 02 02 02 02 04 03 03 02
0020 03 05 04 05 05 05 04 04 04 05 06 07 06 05 05 07
0030 06 04 04 06 09 06 07 08 08 08 08 08 05 06 09 0d
0040 0a 09 08 0d 0a 07 08 08 08 01 01 01 01 02 02 02
0050 04 02 02 04 08 05 04 05 08 08 08 08 08 08 08 08
0060 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
0070 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08 08
... [snip 12208 bytes]
3030 0f b3 84 8e 46 65 56 51 b5 99 f9 43 9c 0e 38 f5
3040 af 0b 33 cc 21 87 a5 2a d3 d9 7e a4 61 30 92 af
3050 53 d9 43 e2 67 d1 ff 00 b5 cf ec 3c 7f 66 6f d9
3060 d7 c3 1a 0f 8b 7c 47 a5 ea 9f 10 ff 00 e1 22 37
3070 97 33 d9 07 78 1f cd 87 6f 93 1e e0 09 0d 0a b1
3080 a9 2c 40 c9 07 8e 95 f9 4d 37 85 a7 40 42 de 5b
3090 bf 1d d5 85 61 94 42 58 ca 1f 58 8b b2 6d ee 74
30a0 66 d4 be af 51 53 9e ad 25 fa 9f ff d9
[Originally posted by exiftool on 2008-08-18 15:47:52-07]Ah, yes. The age-old newline problem.
You must set your file to binary output or the newlines
are translated:
open (OUT, '>perl.jpg') or die "cannot open perl.jpg";
binmode OUT;
print OUT $$val;
- Phil
[Originally posted by rkunesch on 2008-08-18 16:06:44-07]
;-)
now it workes wonderfully.
Thanks a lot and many greetings from Switzerland,
Ralph