Uploaded image for project: 'Tika'
  1. Tika
  2. TIKA-2630

Wrong height and width metadata for JPEG images

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.17
    • Fix Version/s: None
    • Component/s: parser
    • Labels:
      None

      Description

      According to Exif specs, for compressed images the values for width and height should come from the tags:

      • PixelXDimension mapped in metadata-extractor to com.drew.metadata.Directory.ExifDirectoryBase.TAG_EXIF_IMAGE_WIDTH and
      • PixelYDimension mapped to ExifDirectoryBase.TAG_EXIF_IMAGE_HEIGHT.

      ImageMetadataExtractor$ExifHandler.handlePhotoTags(...) should extract and set these in the metadata:

       if (directory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)) {
          metadata.set(Metadata.IMAGE_WIDTH,
                       trimPixels(directory.getDescription(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)));
        }
        if (directory.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)) {
            metadata.set(Metadata.IMAGE_LENGTH,
                         trimPixels(directory.getDescription(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)));
         }
      

      Also the CopyUnknownFieldsHandler overrides the values for "Image Width" (JpegDirectory.TAG_IMAGE_WIDTH) and "Image Height" (JpegDirectory.TAG_IMAGE_HEIGHT) with the values from ExifIFD0Descriptor.TAG_IMAGE_WIDTH and ExifIFD0Descriptor.TAG_IMAGE_HEIGHT because they have the same tag name.

      I attached a sample image, these are the metadata values:

      • extracted by metadata-extractor:
        [JPEG] Image Height = 367 pixels
        [JPEG] Image Width = 1535 pixels
        [Exif IFD0] Image Width = 2173 pixels
        [Exif IFD0] Image Height = 520 pixels
        [Exif SubIFD] Exif Image Width = 1535 pixels
        [Exif SubIFD] Exif Image Height = 367 pixels
      • Tika metadata:
        Image Height: 520 pixels
        Image Width: 2173 pixels
        tiff:ImageLength: 520
        tiff:ImageWidth: 2173
        Exif Image Height: 367 pixels
        Exif Image Width: 1535 pixels

        Attachments

        1. Tika-metadata.txt
          3 kB
          Ancuta Morarasu
        2. sizesampleissue.jpg
          578 kB
          Ancuta Morarasu
        3. metadata-exctractor-metadata.txt
          4 kB
          Ancuta Morarasu

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              ancuta.morarasu Ancuta Morarasu
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: