From 6c84a1109dd3761a9dac80fa48344469c63def33 Mon Sep 17 00:00:00 2001 From: Nelson Silva Date: Wed, 22 May 2013 18:38:41 +0100 Subject: [PATCH] NXP-11582: Rely on metadata-extractor alone to extract metadata from images --- .../picture/api/MetadataConstants.java | 4 - .../api/adapters/AbstractPictureAdapter.java | 8 - .../nuxeo-platform-imaging-core/pom.xml | 12 +- .../ecm/platform/picture/IPTCHelper.java | 78 ++----- .../platform/picture/ImagingComponent.java | 3 +- .../core/mistral/MistralMetadataUtils.java | 209 +++++++++++------- .../picture/core/test/TestExifHelper.java | 2 +- .../core/test/TestMetaDataService.java | 2 - 8 files changed, 144 insertions(+), 174 deletions(-) diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/MetadataConstants.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/MetadataConstants.java index 31c139d0df..7f0a179475 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/MetadataConstants.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/MetadataConstants.java @@ -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"; diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java index b79ae7b6c1..fd75a704f8 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-api/src/main/java/org/nuxeo/ecm/platform/picture/api/adapters/AbstractPictureAdapter.java @@ -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; @@ -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.*; @@ -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 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, diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/pom.xml b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/pom.xml index a94652011c..884fe7bf12 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/pom.xml +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/pom.xml @@ -43,16 +43,10 @@ - net.java.dev.mistral - EditableImage - - - net.java.dev.mistral - Operations - - - net.java.dev.mistral + com.drewnoakes metadata-extractor + + 2.6.4 diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/IPTCHelper.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/IPTCHelper.java index 7afdfb3a63..eb1d7a2e66 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/IPTCHelper.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/IPTCHelper.java @@ -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 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 metadata) throws MetadataException { - public static void extractMetadataFromSegment(Map metadata, - JpegSegmentReader reader, byte marker, - Class klass) { - try { - Constructor 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 metadata) { - Directory iptc = md.getDirectory(IptcDirectory.class); + if (iptc == null) { + return; + } if (iptc.containsTag(IptcDirectory.TAG_BY_LINE)) { metadata.put(META_BY_LINE, @@ -137,10 +96,10 @@ public static void extract(Metadata md, Map 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)) { @@ -149,12 +108,8 @@ public static void extract(Metadata md, Map 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)) { @@ -200,19 +155,16 @@ public static void extract(Metadata md, Map 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)) { @@ -247,9 +199,9 @@ public static void extract(Metadata md, Map 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))); } } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/ImagingComponent.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/ImagingComponent.java index 78164aff3a..3d5fa50060 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/ImagingComponent.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/ImagingComponent.java @@ -106,8 +106,7 @@ public Blob rotate(Blob blob, int angle) { @Override public Map getImageMetadata(Blob blob) { try { - return getLibrarySelectorService().getMetadataUtils().getImageMetadata( - blob); + return getLibrarySelectorService().getMetadataUtils().getImageMetadata(blob); } catch (Exception e) { log.error(e.getMessage(), e); } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/core/mistral/MistralMetadataUtils.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/core/mistral/MistralMetadataUtils.java index a44ee1e5fb..f62e14db36 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/core/mistral/MistralMetadataUtils.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/main/java/org/nuxeo/ecm/platform/picture/core/mistral/MistralMetadataUtils.java @@ -27,7 +27,6 @@ import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_EXPOSURE; 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_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; @@ -37,12 +36,8 @@ import static org.nuxeo.ecm.platform.picture.api.MetadataConstants.META_PIXEL_YDIMENSION; 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 it.tidalwave.image.EditableImage; -import it.tidalwave.image.Rational; -import it.tidalwave.image.metadata.EXIFDirectory; -import it.tidalwave.image.op.ReadOp; +import java.io.BufferedInputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -50,11 +45,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuxeo.ecm.core.api.Blob; -import org.nuxeo.ecm.platform.picture.ExifHelper; import org.nuxeo.ecm.platform.picture.IPTCHelper; import org.nuxeo.ecm.platform.picture.core.MetadataUtils; -import com.drew.imaging.jpeg.JpegProcessingException; +import com.drew.imaging.ImageMetadataReader; +import com.drew.imaging.ImageProcessingException; +import com.drew.lang.Rational; +import com.drew.metadata.Metadata; +import com.drew.metadata.MetadataException; +import com.drew.metadata.exif.ExifIFD0Directory; +import com.drew.metadata.exif.ExifSubIFDDescriptor; +import com.drew.metadata.exif.ExifSubIFDDirectory; /** * @@ -66,130 +67,168 @@ public class MistralMetadataUtils implements MetadataUtils { private static final Log log = LogFactory.getLog(MistralMetadataUtils.class); - private static final String JPEG_MIMETYPE = "image/jpeg"; - @Override public Map getImageMetadata(Blob blob) { + Map metadata = new HashMap(); + Metadata imageMetadata = null; + + try { + imageMetadata = ImageMetadataReader.readMetadata(new BufferedInputStream(blob.getStream()), false); + } catch (IOException | ImageProcessingException e) { + log.error("Failed to read metadata for the file:" + + blob.getFilename(), e); + } + + if (imageMetadata == null) { + return metadata; + } + + /* EXIF */ + try { + metadata.putAll(extractEXIF(imageMetadata)); + } catch (MetadataException e) { + log.error("Failed to get EXIF metadata for the file:" + + blob.getFilename(), e); + } + + /* IPTC */ try { - EditableImage image = EditableImage.create(new ReadOp( - blob.getStream(), ReadOp.Type.METADATA)); - EXIFDirectory exif = image.getEXIFDirectory(); - - // CB: NXP-4348 - Return correct values for image width/height - image = EditableImage.create(new ReadOp(blob.getStream())); - metadata.put(META_WIDTH, image.getWidth()); - metadata.put(META_HEIGHT, image.getHeight()); - - /* EXIF */ - if (exif.isImageDescriptionAvailable()) { - String description = exif.getImageDescription().trim(); + metadata.putAll(extractIPTC(imageMetadata)); + } catch (MetadataException e) { + log.error("Failed to get IPTC metadata for the file:" + + blob.getFilename(), e); + } + + return metadata; + } + + + protected Map extractEXIF(Metadata imageMetadata) throws MetadataException { + + Map metadata = new HashMap(); + + ExifIFD0Directory exifIFD0 = imageMetadata.getDirectory(ExifIFD0Directory.class); + + if (exifIFD0 != null) { + + // Description + if (exifIFD0.containsTag(ExifIFD0Directory.TAG_IMAGE_DESCRIPTION)) { + String description = exifIFD0.getString(ExifIFD0Directory.TAG_IMAGE_DESCRIPTION).trim(); if (description.length() > 0) { metadata.put(META_DESCRIPTION, description); } } - if (exif.isUserCommentAvailable()) { - String comment = ExifHelper.decodeUndefined( - exif.getUserComment()).trim(); - if (comment.length() > 0) { - metadata.put(META_COMMENT, comment); - } - } - - if (exif.isMakeAvailable() || exif.isModelAvailable()) { - String equipment = (exif.getMake() + " " + exif.getModel()).trim(); + // Make and model + if (exifIFD0.containsTag(ExifIFD0Directory.TAG_MAKE) || exifIFD0.containsTag(ExifIFD0Directory.TAG_MODEL)) { + String equipment = (exifIFD0.getString(ExifIFD0Directory.TAG_MAKE) + " " + exifIFD0.getString(ExifIFD0Directory.TAG_MODEL)).trim(); if (equipment.length() > 0) { metadata.put(META_EQUIPMENT, equipment); } } - if (exif.isDateTimeOriginalAvailable()) { + // Date + if (exifIFD0.containsTag(ExifIFD0Directory.TAG_DATETIME)) { metadata.put(META_ORIGINALDATE, - exif.getDateTimeOriginalAsDate()); - } - - if (exif.isXResolutionAvailable() && exif.isYResolutionAvailable()) { - metadata.put(META_HRESOLUTION, exif.getXResolution().intValue()); - metadata.put(META_VRESOLUTION, exif.getYResolution().intValue()); + exifIFD0.getDate(ExifIFD0Directory.TAG_DATETIME)); } - if (exif.isPixelXDimensionAvailable() - && exif.isPixelYDimensionAvailable()) { - metadata.put(META_PIXEL_XDIMENSION, exif.getPixelXDimension()); - metadata.put(META_PIXEL_YDIMENSION, exif.getPixelYDimension()); + // Resolution + if (exifIFD0.containsTag(ExifIFD0Directory.TAG_X_RESOLUTION) && exifIFD0.containsTag(ExifIFD0Directory.TAG_Y_RESOLUTION)) { + metadata.put(META_HRESOLUTION, exifIFD0.getInt(ExifIFD0Directory.TAG_X_RESOLUTION)); + metadata.put(META_VRESOLUTION, exifIFD0.getInt(ExifIFD0Directory.TAG_Y_RESOLUTION)); } - if (exif.isCopyrightAvailable()) { - String copyright = exif.getCopyright().trim(); + // Copyright + if (exifIFD0.containsTag(ExifIFD0Directory.TAG_COPYRIGHT)) { + String copyright = exifIFD0.getString(ExifIFD0Directory.TAG_COPYRIGHT).trim(); if (copyright.length() > 0) { metadata.put(META_COPYRIGHT, copyright); } } - if (exif.isExposureTimeAvailable()) { - Rational exposure = exif.getExposureTime(); - int n = exposure.getNumerator(); - int d = exposure.getDenominator(); + if (exifIFD0.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) { + metadata.put(META_ORIENTATION, exifIFD0.getString(ExifIFD0Directory.TAG_ORIENTATION)); + } + + } + + /* EXIF from the SubIFD directory */ + + ExifSubIFDDirectory exifSubIFD = imageMetadata.getDirectory(ExifSubIFDDirectory.class); + + if (exifSubIFD != null) { + + ExifSubIFDDescriptor descriptor = new ExifSubIFDDescriptor(exifSubIFD); + + // User comment + String comment = descriptor.getUserCommentDescription(); + if (comment != null) { + metadata.put(META_COMMENT, comment); + } + + // Dimensions + if (exifSubIFD.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH) && exifSubIFD.containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)) { + metadata.put(META_PIXEL_XDIMENSION, exifSubIFD.getInt(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH)); + metadata.put(META_PIXEL_YDIMENSION, exifSubIFD.getInt(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)); + } + + // Exposure + if (exifSubIFD.containsTag(ExifSubIFDDirectory.TAG_EXPOSURE_TIME)) { + Rational exposure = exifSubIFD.getRational(ExifSubIFDDirectory.TAG_EXPOSURE_TIME); + long n = exposure.getNumerator(); + long d = exposure.getDenominator(); if (d >= n && d % n == 0) { exposure = new Rational(1, d / n); } metadata.put(META_EXPOSURE, exposure.toString()); } - if (exif.isISOSpeedRatingsAvailable()) { - metadata.put(META_ISOSPEED, "ISO-" + exif.getISOSpeedRatings()); + // ISO + String iso = descriptor.getIsoEquivalentDescription(); + if (iso != null) { + metadata.put(META_ISOSPEED, "ISO-" + iso); } - if (exif.isFocalLengthAvailable()) { + // Focal length + if (exifSubIFD.containsTag(ExifSubIFDDirectory.TAG_FOCAL_LENGTH)) { metadata.put(META_FOCALLENGTH, - exif.getFocalLength().doubleValue()); + exifSubIFD.getRational(ExifSubIFDDirectory.TAG_FOCAL_LENGTH).doubleValue()); } - if (exif.isColorSpaceAvailable()) { - metadata.put(META_COLORSPACE, exif.getColorSpace().toString()); + // Color space + String colorSpace = descriptor.getColorSpaceDescription(); + if (colorSpace != null) { + metadata.put(META_COLORSPACE, colorSpace); } - if (exif.isWhiteBalanceAvailable()) { - metadata.put(META_WHITEBALANCE, - exif.getWhiteBalance().toString().toLowerCase()); + // White balance mode + String whiteBalanceMode = descriptor.getWhiteBalanceModeDescription(); + if (whiteBalanceMode != null) { + metadata.put(META_WHITEBALANCE, whiteBalanceMode); } - if (exif.isInterColourProfileAvailable()) { - metadata.put(META_ICCPROFILE, exif.getICCProfile()); - } - if (exif.isOrientationAvailable()) { - metadata.put(META_ORIENTATION, exif.getOrientation().toString()); + // ICC profile + if (exifSubIFD.containsTag(ExifSubIFDDirectory.TAG_INTER_COLOR_PROFILE)) { + metadata.put(META_ICCPROFILE, exifSubIFD.getString(ExifSubIFDDirectory.TAG_INTER_COLOR_PROFILE)); } - if (exif.isFNumberAvailable()) { - metadata.put(META_FNUMBER, exif.getFNumber().doubleValue()); + // F-stop + if (exifSubIFD.containsTag(ExifSubIFDDirectory.TAG_FNUMBER)) { + metadata.put(META_FNUMBER, + exifSubIFD.getRational(ExifSubIFDDirectory.TAG_FNUMBER).doubleValue()); } - } catch (IOException e) { - log.warn("Failed to get EXIF metadata for the file: " - + blob.getFilename()); - log.debug( - "Failed to get EXIF metadata for the file: " - + blob.getFilename(), e); } - try { - /* IPTC */ - if (JPEG_MIMETYPE.equals(blob.getMimeType())) { - IPTCHelper.extractMetadata(blob.getStream(), metadata); - } - } catch (IOException e) { - log.error( - "Failed to get IPTC metadata for the file:" - + blob.getFilename(), e); - } catch (JpegProcessingException e) { - log.error( - "Failed to get IPTC metadata for the file:" - + blob.getFilename(), e); - } + return metadata; + } + protected Map extractIPTC(Metadata imageMetadata) throws MetadataException { + Map metadata = new HashMap(); + IPTCHelper.extract(imageMetadata, metadata); return metadata; } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestExifHelper.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestExifHelper.java index 1c4528d423..629a70db29 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestExifHelper.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestExifHelper.java @@ -82,6 +82,6 @@ public void testUserCommentExifDataType() { Map metadatas = service.getImageMetadata(blob); String userComment = ((String) metadatas.get(MetadataConstants.META_COMMENT)).trim(); assertNotSame("ASCII", userComment); - assertEquals("(C) PAULO BRANDA", userComment); + assertEquals("(C) PAULO BRANDAO", userComment); } } diff --git a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMetaDataService.java b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMetaDataService.java index 5e6790351b..8902911c7c 100644 --- a/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMetaDataService.java +++ b/nuxeo-platform-imaging/nuxeo-platform-imaging-core/src/test/java/org/nuxeo/ecm/platform/picture/core/test/TestMetaDataService.java @@ -79,11 +79,9 @@ public void testMetaData() throws Exception { assertNotNull(map.get(MetadataConstants.META_CREDIT)); assertNotNull(map.get(MetadataConstants.META_DATE_CREATED)); assertNotNull(map.get(MetadataConstants.META_HEADLINE)); - assertNotNull(map.get(MetadataConstants.META_HEIGHT)); assertNotNull(map.get(MetadataConstants.META_OBJECT_NAME)); assertNotNull(map.get(MetadataConstants.META_SOURCE)); assertNotNull(map.get(MetadataConstants.META_SUPPLEMENTAL_CATEGORIES)); - assertNotNull(map.get(MetadataConstants.META_WIDTH)); // those metadata are not found by the parser // assertNotNull(map.get(MetadataConstants.META_COMMENT));