use of com.day.cq.dam.commons.util.PrefixRenditionPicker in project acs-aem-commons by Adobe-Consulting-Services.
the class AbstractRenditionModifyingProcess method execute.
public final void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaData, WorkflowHelper workflowHelper) throws WorkflowException {
String[] args = workflowHelper.buildArguments(metaData);
final String renditionName = workflowHelper.getValuesFromArgs(ARG_RENDITION_NAME, args).size() > 0 ? workflowHelper.getValuesFromArgs(ARG_RENDITION_NAME, args).get(0) : null;
// image quality: from 0 t0 100%
final String qualityStr = workflowHelper.getValuesFromArgs(ARG_QUALITY, args).size() > 0 ? workflowHelper.getValuesFromArgs(ARG_QUALITY, args).get(0) : DEFAULT_QUALITY;
if (renditionName == null) {
log.warn("Rendition name was not configured in arguments. Skipping.");
return;
}
final WorkflowHelper.AssetResourceResolverPair pair = workflowHelper.getAssetFromPayload(workItem, workflowSession);
if (pair == null) {
return;
}
final Rendition rendition = pair.asset.getRendition(new PrefixRenditionPicker(renditionName));
if (rendition == null) {
log.warn("Rendition name {} was not available for asset {}. Skipping.", renditionName, pair.asset);
return;
}
Layer layer = null;
try {
layer = new Layer(rendition.getStream());
layer = processLayer(layer, rendition, workflowSession, args);
String mimetype = layer.getMimeType();
double quality = mimetype.equals("image/gif") ? workflowHelper.getQuality(MAX_GIF_QUALITY, qualityStr) : workflowHelper.getQuality(1.0, qualityStr);
saveImage(pair.asset, rendition, layer, mimetype, quality, workflowHelper);
} catch (IIOException e) {
log.warn("Unable to load image layer from " + rendition.getPath(), e);
} catch (IOException e) {
log.warn("Unable to load image layer from " + rendition.getPath(), e);
} finally {
if (layer != null) {
layer.dispose();
layer = null;
}
pair.resourceResolver.close();
}
}
Aggregations