2

I am using the java version 2.8.1 of metadata-extractor to read a CR2 file. According to the dump of tags there is a Exif Thumbnail directory and it claims there is a thumbnail offset and length. However, when I call getThumbnailData() on the ExifThumbnailDirectory object it returns null. Any idea why? The photo was taken with a Canon EOS 70D camera. Code works fine when I am calling it with JPEGs. The source photo file can be found here.

[Exif Thumbnail] - Thumbnail Offset(0x0201) = 80600 bytes
[Exif Thumbnail] - Thumbnail Length(0x0202) = 15272 bytes
[Exif Thumbnail] - Image Width(0x0100) = 5568 pixels
[Exif Thumbnail] - Image Height(0x0101) = 3708 pixels
[Exif Thumbnail] - Bits Per Sample(0x0102) = 16 16 16 bits/component/pixel
[Exif Thumbnail] - Thumbnail Compression(0x0103) = JPEG (old-style)
[Exif Thumbnail] - Photometric Interpretation(0x0106) = RGB
[Exif Thumbnail] - Strip Offsets(0x0111) = 4472188
[Exif Thumbnail] - Samples Per Pixel(0x0115) = 3 samples/pixel
[Exif Thumbnail] - Rows Per Strip(0x0116) = 309 rows/strip
[Exif Thumbnail] - Strip Byte Counts(0x0117) = 22883515 bytes
[Exif Thumbnail] - Planar Configuration(0x011c) = Chunky (contiguous for each subsampling pixel)
[Exif Thumbnail] - Unknown tag (0xc5d9) = 2
[Exif Thumbnail] - Unknown tag (0xc6c5) = 1
[Exif Thumbnail] - Unknown tag (0xc6dc) = 450 301 7 4
[Exif Thumbnail] - Unknown tag (0xc5d8) = 1
[Exif Thumbnail] - Unknown tag (0xc5e0) = 1
[Exif Thumbnail] - Unknown tag (0xc640) = 1 2784 2784
[File] - File Name(0x0001) = foo.CR2
[File] - File Size(0x0002) = 27361411 bytes
Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
Rick Noel
  • 21
  • 2

1 Answers1

2

The getThumbnailData() method should really be removed. It allocates all the data of the thumbnail into memory when most people don't use it. In this case, the CR2 processor doesn't include it.

Your best bet is to use the first two values shown in your question:

[Exif Thumbnail] - Thumbnail Offset(0x0201) = 80600 bytes
[Exif Thumbnail] - Thumbnail Length(0x0202) = 15272 bytes

With these, and the original file, you can pull out the byte[] for the image. At least, I'm 99% sure you can :)

If not, let me know and we can investigate further.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • I upgraded to ver 2.11.0. I tried your suggestion of using the thumbnail offset using the following code:
    Thumbnails.of(in).size(WIDTH, HEIGHT).outputFormat("jpeg").toOutputStream(out);
    When run on a CR2 file the code works. If I run it on a JPG file it fails with the following exception: net.coobird.thumbnailator.tasks.UnsupportedFormatException: No suitable ImageReader found for source data. If I don't seek to the offset JPG files work but CR2 fail UnsupportedFormatException. How do I get thumbnail from files without the code knowing photo file type?
    – Rick Noel Sep 21 '18 at 05:11