Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIKA-2630: Wrong height and width metadata for JPEG images #255

Merged
merged 3 commits into from Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -260,7 +260,11 @@ public void handle(Directory directory, Metadata metadata)
throws MetadataException {
if (directory.getTags() != null) {
for (Tag tag : directory.getTags()) {
metadata.set(tag.getTagName(), tag.getDescription());
if (directory instanceof ExifDirectoryBase) {
metadata.set(directory.getName() + ":" + tag.getTagName(), tag.getDescription());
} else {
metadata.set(tag.getTagName(), tag.getDescription());
}
}
}
}
Expand Down Expand Up @@ -288,7 +292,11 @@ public void handle(Directory directory, Metadata metadata)
} else if (Boolean.FALSE.toString().equalsIgnoreCase(value)) {
value = Boolean.FALSE.toString();
}
metadata.set(name, value);
if (directory instanceof ExifDirectoryBase) {
metadata.set(directory.getName() + ":" + name, value);
} else {
metadata.set(name, value);
}
}
}
}
Expand Down Expand Up @@ -493,6 +501,17 @@ public void handlePhotoTags(Directory directory, Metadata metadata) {
metadata.set(Metadata.IMAGE_LENGTH,
trimPixels(directory.getDescription(ExifThumbnailDirectory.TAG_IMAGE_HEIGHT)));
}

// For Compressed Images read from ExifSubIFDDirectory
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)));
}

}

/**
Expand Down
Expand Up @@ -65,8 +65,8 @@ public void testJPEG() throws Exception {
parser.parse(stream, new DefaultHandler(), metadata, new ParseContext());

// Core EXIF/TIFF tags
assertEquals("100", metadata.get(Metadata.IMAGE_WIDTH));
assertEquals("68", metadata.get(Metadata.IMAGE_LENGTH));
assertEquals("3888", metadata.get(Metadata.IMAGE_WIDTH));
assertEquals("2592", metadata.get(Metadata.IMAGE_LENGTH));
assertEquals("8", metadata.get(Metadata.BITS_PER_SAMPLE));
assertEquals(null, metadata.get(Metadata.SAMPLES_PER_PIXEL));

Expand All @@ -86,7 +86,7 @@ public void testJPEG() throws Exception {
// Check that EXIF/TIFF tags come through with their raw values too
// (This may be removed for Tika 1.0, as we support more of them
// with explicit Metadata entries)
assertEquals("Canon EOS 40D", metadata.get("Model"));
assertEquals("Canon EOS 40D", metadata.get("Exif IFD0:Model"));

// Common tags
assertEquals("2009-10-02T23:02:49", metadata.get(Metadata.LAST_MODIFIED));
Expand Down Expand Up @@ -120,8 +120,8 @@ public void testJPEGGeo() throws Exception {
assertEquals("-54.1234", metadata.get(Metadata.LONGITUDE));

// Core EXIF/TIFF tags
assertEquals("100", metadata.get(Metadata.IMAGE_WIDTH));
assertEquals("68", metadata.get(Metadata.IMAGE_LENGTH));
assertEquals("3888", metadata.get(Metadata.IMAGE_WIDTH));
assertEquals("2592", metadata.get(Metadata.IMAGE_LENGTH));
assertEquals("8", metadata.get(Metadata.BITS_PER_SAMPLE));
assertEquals(null, metadata.get(Metadata.SAMPLES_PER_PIXEL));

Expand Down
Expand Up @@ -255,7 +255,7 @@ public void getNormalMetadataToo() throws Exception {
m = getXML("testTIFF.tif").metadata;
assertEquals("100", m.get(Metadata.IMAGE_WIDTH));
assertEquals("75", m.get(Metadata.IMAGE_LENGTH));
assertEquals("72 dots per inch", m.get("Y Resolution"));
assertEquals("72 dots per inch", m.get("Exif IFD0:Y Resolution"));
}

//TODO: add unit tests for jp2/jpx/ppm TIKA-2174
Expand Down
Expand Up @@ -468,8 +468,8 @@ public void testRegularImages() throws Exception {
assertEquals("false", meta_jpg.get(RTFMetadata.THUMBNAIL));
assertEquals("false", meta_jpg_exif.get(RTFMetadata.THUMBNAIL));

assertEquals(51, meta_jpg.names().length);
assertEquals(115, meta_jpg_exif.names().length);
assertEquals(50, meta_jpg.names().length);
assertEquals(116, meta_jpg_exif.names().length);
}

@Test
Expand Down