Get ICC Profile information from asset

Avatar

Avatar
Validate 1
Level 1
marcinn
Level 1

Likes

2 likes

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
marcinn
Level 1

Likes

2 likes

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
marcinn
Level 1

10-03-2021

Hi

 

I'm trying to get ICC PRofile information from the asset, but with no luck. Is there any way to grab those fields during asset processing inside a workflow step? 

 

I have a code like that to get an asset object (it's just to describe my problem) implemented inside a class that inherits from WorkflowProcess:

 

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();

 And in the last line, I can't see metadata ICC fields. 

 

Any suggestions? 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 1
marcinn
Level 1

Likes

2 likes

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
marcinn
Level 1

Likes

2 likes

Total Posts

9 posts

Correct reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
marcinn
Level 1

22-03-2021

OK, finally resolved

 

I've used this library 

org.apache.commons.imaging 

 and then it was easy

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();
}

 

Answers (0)