从 Adob​​e Experience Manager 资产获取 ICC 配置文件信息

Get ICC Profile information from Adobe Experience Manager asset

我正在尝试从资产中获取 ICC PRofile 信息,但没有成功。有什么方法可以在工作流步骤中的资产处理过程中获取这些字段吗?

我有一个类似的代码来获取资产对象(它只是为了描述我的问题)在继承自 WorkflowProcess 的 class 中实现:

 ResourceResolver resolver = workflowSession.adaptTo(ResourceResolver.class);

String path = workItem.getWorkflowData().getPayload().toString();
if (StringUtils.contains(path, JcrConstants.JCR_CONTENT)) {
    path = StringUtils.substringBefore(path, JcrConstants.JCR_CONTENT);
}

Resource resource = resolver.getResource(path);
Asset asset = resource == null ? null : resource.adaptTo(Asset.class);

if (asset == null) {
    log.info("Asset is null, skipping metadata extraction");
}

assert asset != null;
String layerName = asset.getMetadata("photoshop:LayerName") != null ? asset.getMetadata("photoshop:LayerName").toString() : "";

Map<String, Object> meta = asset.getMetadata();

在最后一行,我看不到元数据 ICC 字段。

有什么建议吗?

好的,终于解决了

我用过这个库

org.apache.commons.imaging 

然后很容易

Asset asset = resource == null ? null : resource.adaptTo(Asset.class);
Iterator<? extends Rendition> rendition = asset.listRenditions();
if (rendition.hasNext()) {
    Rendition ren = rendition.next();

    try {
        byte[] assetByteArray = new byte[ren.getStream().available()];
        ren.getStream().read(assetByteArray);

        Imaging.getImageInfo(assetByteArray).getColorType();

        ICC_Profile iccProfile = Imaging.getICCProfile(assetByteArray);
        if (iccProfile != null) {
            int cs = iccProfile.getColorSpaceType();

            String colorSpaceName = getColorSpaceName(cs);

            Resource assetResource = resolver.getResource(path);
            Resource metadatResource = assetResource.getChild(DamConstants.METADATA_PATH);

            ModifiableValueMap mvmForAsset = metadatResource.adaptTo(ModifiableValueMap.class);
            mvmForAsset.put(DamConstants.ASSET_COLORSPACE, colorSpaceName);

            try {
                resolver.commit();
            } catch (PersistenceException e) {
                log.error("Error occurred during saving metadata value {}", e.getMessage());
            } finally {
                resolver.close();
            }