Search in sources :

Example 16 with ImageTransformationOptions

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);
}
Also used : ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions)

Example 17 with ImageTransformationOptions

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));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 18 with ImageTransformationOptions

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 19 with ImageTransformationOptions

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);
}
Also used : ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions)

Example 20 with ImageTransformationOptions

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);
}
Also used : HashMap(java.util.HashMap) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) RuntimeExec(org.alfresco.util.exec.RuntimeExec) File(java.io.File) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException)

Aggregations

ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)35 Test (org.junit.Test)26 ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)22 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 PagedSourceOptions (org.alfresco.service.cmr.repository.PagedSourceOptions)8 HashMap (java.util.HashMap)7 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)7 CropSourceOptions (org.alfresco.service.cmr.repository.CropSourceOptions)7 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)7 Serializable (java.io.Serializable)5 SWFTransformationOptions (org.alfresco.repo.content.transform.swf.SWFTransformationOptions)4 TemporalSourceOptions (org.alfresco.service.cmr.repository.TemporalSourceOptions)3 TransformationSourceOptions (org.alfresco.service.cmr.repository.TransformationSourceOptions)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 RuntimeExecutableContentTransformerOptions (org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerOptions)2 ThumbnailParentAssociationDetails (org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails)2 BufferedImage (java.awt.image.BufferedImage)1 Arrays (java.util.Arrays)1