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

NXP-11582: Updated metadata-extractor and removed older mistral references #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
*/
public class MetadataConstants {

public static final String META_WIDTH = "width";

public static final String META_HEIGHT = "height";

/* EXIF */
public static final String META_DESCRIPTION = "description";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_FNUMBER;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_FOCALLENGTH;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_HEADLINE;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_HEIGHT;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_HRESOLUTION;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_ICCPROFILE;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_ISOSPEED;
Expand All @@ -66,7 +65,6 @@
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_URGENCY;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_VRESOLUTION;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_WHITEBALANCE;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_WIDTH;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_WRITER;

import java.awt.*;
Expand Down Expand Up @@ -198,21 +196,15 @@ protected CoreSession getSession() {
}

protected void setMetadata() throws IOException, ClientException {
boolean imageInfoUsed = false;
ImageInfo imageInfo = getImagingService().getImageInfo(fileContent);
if (imageInfo != null) {
width = imageInfo.getWidth();
height = imageInfo.getHeight();
depth = imageInfo.getDepth();
imageInfoUsed = true;
}
Map<String, Object> metadata = getImagingService().getImageMetadata(
fileContent);
description = (String) metadata.get(META_DESCRIPTION);
if (!imageInfoUsed) {
width = (Integer) metadata.get(META_WIDTH);
height = (Integer) metadata.get(META_HEIGHT);
}
doc.setPropertyValue("picture:" + FIELD_BYLINE,
(String) metadata.get(META_BY_LINE));
doc.setPropertyValue("picture:" + FIELD_CAPTION,
Expand Down
12 changes: 3 additions & 9 deletions nuxeo-platform-imaging/nuxeo-platform-imaging-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@

<!-- Mistral -->
<dependency>
<groupId>net.java.dev.mistral</groupId>
<artifactId>EditableImage</artifactId>
</dependency>
<dependency>
<groupId>net.java.dev.mistral</groupId>
<artifactId>Operations</artifactId>
</dependency>
<dependency>
<groupId>net.java.dev.mistral</groupId>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
<!-- TODO: Move the version to dependency management -->
<version>2.6.4</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,62 +48,21 @@
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_URGENCY;
import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_WRITER;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.drew.imaging.jpeg.JpegProcessingException;
import com.drew.imaging.jpeg.JpegSegmentReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.MetadataException;
import com.drew.metadata.MetadataReader;
import com.drew.metadata.exif.ExifReader;
import com.drew.metadata.iptc.IptcDirectory;
import com.drew.metadata.iptc.IptcReader;
import com.drew.metadata.jpeg.JpegCommentReader;
import com.drew.metadata.jpeg.JpegReader;

public class IPTCHelper {

private static final Log log = LogFactory.getLog(IPTCHelper.class);

public static void extractMetadata(InputStream stream,
Map<String, Object> metadata) throws JpegProcessingException {
JpegSegmentReader reader = new JpegSegmentReader(stream);
extractMetadataFromSegment(metadata, reader,
JpegSegmentReader.SEGMENT_APP1, ExifReader.class);
extractMetadataFromSegment(metadata, reader,
JpegSegmentReader.SEGMENT_APPD, IptcReader.class);
extractMetadataFromSegment(metadata, reader,
JpegSegmentReader.SEGMENT_SOF0, JpegReader.class);
extractMetadataFromSegment(metadata, reader,
JpegSegmentReader.SEGMENT_COM, JpegCommentReader.class);
}
public static void extract(Metadata md, Map<String, Object> metadata) throws MetadataException {

public static void extractMetadataFromSegment(Map<String, Object> metadata,
JpegSegmentReader reader, byte marker,
Class<? extends MetadataReader> klass) {
try {
Constructor<? extends MetadataReader> constructor = klass.getConstructor(byte[].class);
int n = reader.getSegmentCount(marker);
for (int i = 0; i < n; i++) {
byte[] segment = reader.readSegment(marker, i);

Metadata md = new Metadata();
constructor.newInstance(segment).extract(md);
extract(md, metadata);
}
} catch (Exception e) {
// Unable to read this kind of metadata, so skip
}
}
IptcDirectory iptc = md.getDirectory(IptcDirectory.class);

public static void extract(Metadata md, Map<String, Object> metadata) {
Directory iptc = md.getDirectory(IptcDirectory.class);
if (iptc == null) {
return;
}

if (iptc.containsTag(IptcDirectory.TAG_BY_LINE)) {
metadata.put(META_BY_LINE,
Expand Down Expand Up @@ -137,10 +96,10 @@ public static void extract(Metadata md, Map<String, Object> metadata) {
cleanupData(iptc.getString(IptcDirectory.TAG_COPYRIGHT_NOTICE)));
}

if (iptc.containsTag(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION)) {
if (iptc.containsTag(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME)) {
metadata.put(
META_COUNTRY_OR_PRIMARY_LOCATION,
cleanupData(iptc.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION)));
cleanupData(iptc.getString(IptcDirectory.TAG_COUNTRY_OR_PRIMARY_LOCATION_NAME)));
}

if (iptc.containsTag(IptcDirectory.TAG_CREDIT)) {
Expand All @@ -149,12 +108,8 @@ public static void extract(Metadata md, Map<String, Object> metadata) {
}

if (iptc.containsTag(IptcDirectory.TAG_DATE_CREATED)) {
try {
metadata.put(META_DATE_CREATED,
metadata.put(META_DATE_CREATED,
iptc.getDate(IptcDirectory.TAG_DATE_CREATED));
} catch (MetadataException e) {
log.error("Failed to get IPTC - date created", e);
}
}

if (iptc.containsTag(IptcDirectory.TAG_HEADLINE)) {
Expand Down Expand Up @@ -200,19 +155,16 @@ public static void extract(Metadata md, Map<String, Object> metadata) {
cleanupData(iptc.getString(IptcDirectory.TAG_PROVINCE_OR_STATE)));
}

if (iptc.containsTag(IptcDirectory.TAG_RECORD_VERSION)) {
if (iptc.containsTag(IptcDirectory.TAG_APPLICATION_RECORD_VERSION)) {
metadata.put(
META_RECORD_VERSION,
cleanupData(iptc.getString(IptcDirectory.TAG_RECORD_VERSION)));
cleanupData(iptc.getString(IptcDirectory.TAG_APPLICATION_RECORD_VERSION)));
}

if (iptc.containsTag(IptcDirectory.TAG_RELEASE_DATE)) {
try {
metadata.put(META_RELEASE_DATE,
iptc.getDate(IptcDirectory.TAG_RELEASE_DATE));
} catch (MetadataException e) {
log.error("Failed to get IPTC - release date", e);
}
metadata.put(
META_RELEASE_DATE,
iptc.getDate(IptcDirectory.TAG_RELEASE_DATE));
}

if (iptc.containsTag(IptcDirectory.TAG_RELEASE_TIME)) {
Expand Down Expand Up @@ -247,9 +199,9 @@ public static void extract(Metadata md, Map<String, Object> metadata) {
cleanupData(iptc.getString(IptcDirectory.TAG_URGENCY)));
}

if (iptc.containsTag(IptcDirectory.TAG_WRITER)) {
if (iptc.containsTag(IptcDirectory.TAG_CAPTION_WRITER)) {
metadata.put(META_WRITER,
cleanupData(iptc.getString(IptcDirectory.TAG_WRITER)));
cleanupData(iptc.getString(IptcDirectory.TAG_CAPTION_WRITER)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public Blob rotate(Blob blob, int angle) {
@Override
public Map<String, Object> getImageMetadata(Blob blob) {
try {
return getLibrarySelectorService().getMetadataUtils().getImageMetadata(
blob);
return getLibrarySelectorService().getMetadataUtils().getImageMetadata(blob);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down
Loading