use of org.alfresco.repo.content.transform.magick.ImageTransformationOptions in project alfresco-repository by Alfresco.
the class ImageRenderingEngine method getTransformOptionsImpl.
@Override
protected TransformationOptions getTransformOptionsImpl(TransformationOptions options, RenderingContext context) {
options.setSourceNodeRef(context.getSourceNode());
ImageTransformationOptions imageTransformationOptions = (ImageTransformationOptions) options;
String commandOptions = context.getCheckedParam(PARAM_COMMAND_OPTIONS, String.class);
ImageResizeOptions imageResizeOptions = getImageResizeOptions(context);
boolean autoOrient = context.getParamWithDefault(PARAM_AUTO_ORIENTATION, true);
imageTransformationOptions.setResizeOptions(imageResizeOptions);
imageTransformationOptions.setAutoOrient(autoOrient);
if (commandOptions != null) {
imageTransformationOptions.setCommandOptions(commandOptions);
}
return super.getTransformOptionsImpl(options, context);
}
use of org.alfresco.repo.content.transform.magick.ImageTransformationOptions in project alfresco-repository by Alfresco.
the class ThumbnailServiceImplTest method testThumbnailUpdate.
@Test
public void testThumbnailUpdate() throws Exception {
checkTransformer();
// First create a thumbnail
NodeRef jpgOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
imageResizeOptions.setWidth(64);
imageResizeOptions.setHeight(64);
imageResizeOptions.setResizeToThumbnail(true);
ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions();
imageTransformationOptions.setResizeOptions(imageResizeOptions);
NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "small");
// Thumbnails should always be of type cm:thumbnail.
assertEquals(ContentModel.TYPE_THUMBNAIL, secureNodeService.getType(thumbnail1));
// Update the thumbnail
this.thumbnailService.updateThumbnail(thumbnail1, imageTransformationOptions);
// ALF-2047. Thumbnails were changing to type cm:content after update.
assertEquals(ContentModel.TYPE_THUMBNAIL, secureNodeService.getType(thumbnail1));
}
use of org.alfresco.repo.content.transform.magick.ImageTransformationOptions in project alfresco-repository by Alfresco.
the class ThumbnailServiceImplTest method testGetThumbnailByName.
@Test
public void testGetThumbnailByName() throws Exception {
checkTransformer();
NodeRef jpgOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
// Check for missing thumbnail
NodeRef result1 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "small");
assertNull("The thumbnail 'small' should have been missing", result1);
// Create the thumbnail
ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
imageResizeOptions.setWidth(64);
imageResizeOptions.setHeight(64);
imageResizeOptions.setResizeToThumbnail(true);
ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions();
imageTransformationOptions.setResizeOptions(imageResizeOptions);
this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "small");
// Try and retrieve the thumbnail
NodeRef result2 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "small");
assertNotNull(result2);
checkRendition("small", result2);
// Check for an other thumbnail that doesn't exist
NodeRef result3 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "anotherone");
assertNull("The thumbnail 'anotherone' should have been missing", result3);
}
use of org.alfresco.repo.content.transform.magick.ImageTransformationOptions in project alfresco-repository by Alfresco.
the class AlfrescoPdfRendererContentTransformerWorker method transformRemote.
/**
* Transform the pdf content using a remote transformer
*/
private void transformRemote(ContentReader reader, ContentWriter writer, TransformationOptions options, String sourceMimetype, String targetMimetype, String sourceExtension, String targetExtension) throws Exception {
String page = null;
String width = null;
String height = null;
String allowEnlargement = null;
String maintainAspectRatio = null;
if (options instanceof ImageTransformationOptions) {
ImageTransformationOptions imageOptions = (ImageTransformationOptions) options;
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
if (resizeOptions != null) {
if (resizeOptions.getWidth() > -1) {
width = Integer.toString(resizeOptions.getWidth());
}
if (resizeOptions.getHeight() > -1) {
height = Integer.toString(resizeOptions.getHeight());
}
if (resizeOptions.getAllowEnlargement()) {
allowEnlargement = Boolean.TRUE.toString();
}
if (resizeOptions.isMaintainAspectRatio()) {
maintainAspectRatio = Boolean.TRUE.toString();
}
}
page = getSourcePageRange(imageOptions, sourceMimetype, targetMimetype);
}
long timeoutMs = options.getTimeoutMs();
remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension, timeoutMs, logger, "transformName", "pdfrenderer", "sourceMimetype", sourceMimetype, "targetMimetype", targetMimetype, "targetExtension", targetExtension, PAGE, page, WIDTH, width, HEIGHT, height, ALLOW_PDF_ENLARGEMENT, allowEnlargement, MAINTAIN_PDF_ASPECT_RATIO, maintainAspectRatio);
}
use of org.alfresco.repo.content.transform.magick.ImageTransformationOptions in project alfresco-repository by Alfresco.
the class AlfrescoPdfRendererContentTransformerWorker method transformLocal.
private void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options, String sourceMimetype, String targetMimetype, String sourceExtension, String targetExtension) throws Exception {
// create required temp files
File sourceFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_source_", "." + sourceExtension);
File targetFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_target_", "." + targetExtension);
// pull reader file into source temp file
reader.getContent(sourceFile);
Map<String, String> properties = new HashMap<String, String>(5);
// set properties
if (options instanceof ImageTransformationOptions) {
ImageTransformationOptions imageOptions = (ImageTransformationOptions) options;
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
String commandOptions = imageOptions.getCommandOptions();
if (commandOptions == null) {
commandOptions = "";
}
if (resizeOptions != null) {
if (resizeOptions.getHeight() > -1) {
commandOptions += " --height=" + resizeOptions.getHeight();
}
if (resizeOptions.getWidth() > -1) {
commandOptions += " --width=" + resizeOptions.getWidth();
}
if (resizeOptions.getAllowEnlargement()) {
commandOptions += " --allow-enlargement";
}
if (resizeOptions.isMaintainAspectRatio()) {
commandOptions += " --maintain-aspect-ratio";
}
}
commandOptions += " --page=" + getSourcePageRange(imageOptions, sourceMimetype, targetMimetype);
properties.put(KEY_OPTIONS, commandOptions);
}
properties.put(VAR_SOURCE, sourceFile.getAbsolutePath());
properties.put(VAR_TARGET, targetFile.getAbsolutePath());
// execute the statement
long timeoutMs = options.getTimeoutMs();
RuntimeExec.ExecutionResult result = executer.execute(properties, timeoutMs);
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0) {
throw new ContentIOException("Failed to perform alfresco-pdf-renderer transformation: \n" + result);
}
// success
if (logger.isDebugEnabled()) {
logger.debug("alfresco-pdf-renderer executed successfully: \n" + executer);
}
// check that the file was created
if (!targetFile.exists() || targetFile.length() == 0) {
throw new ContentIOException("alfresco-pdf-renderer transformation failed to write output file");
}
// upload the output image
writer.putContent(targetFile);
}
Aggregations