Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Get ICC Profile information from asset

marcinn
Level 2
Level 2

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? 

Asset ICCProfile metadata
1 Accepted Solution
marcinn
Correct answer by
Level 2
Level 2

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

 

View solution in original post

2 Replies
marcinn
Correct answer by
Level 2
Level 2

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

 

View solution in original post

kautuk_sahni
Community Manager
Community Manager
@marcinn thnak you for sharing the answer in the AEM community. Keep assisting others here.