Search in sources :

Example 11 with ImageResizeOptions

use of org.alfresco.repo.content.transform.magick.ImageResizeOptions 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 12 with ImageResizeOptions

use of org.alfresco.repo.content.transform.magick.ImageResizeOptions 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 13 with ImageResizeOptions

use of org.alfresco.repo.content.transform.magick.ImageResizeOptions 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 14 with ImageResizeOptions

use of org.alfresco.repo.content.transform.magick.ImageResizeOptions 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)

Example 15 with ImageResizeOptions

use of org.alfresco.repo.content.transform.magick.ImageResizeOptions in project alfresco-repository by Alfresco.

the class ThumbnailRenditionConvertor method convert.

/**
 * Given the specified {@link TransformationOptions transformationOptions} and
 * {@link ThumbnailParentAssociationDetails assocDetails},
 * create and return a parameter Map which contains the equivalent {@link RenditionDefinition}
 * configuration.
 *
 * @param transformationOptions TransformationOptions
 * @param assocDetails ThumbnailParentAssociationDetails
 * @return Map
 */
public Map<String, Serializable> convert(TransformationOptions transformationOptions, ThumbnailParentAssociationDetails assocDetails) {
    Map<String, Serializable> parameters = new HashMap<String, Serializable>();
    // All TransformationOptions-based renditions are considered to be "thumbnails".
    // Therefore they should be created with a node type of cm:thumbnail
    parameters.put(RenditionService.PARAM_RENDITION_NODETYPE, ContentModel.TYPE_THUMBNAIL);
    // parameters common to all transformations
    putParameterIfNotNull(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, transformationOptions.getSourceContentProperty(), parameters);
    putParameterIfNotNull(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, transformationOptions.getTargetContentProperty(), parameters);
    putParameterIfNotNull(RenditionService.PARAM_DESTINATION_NODE, transformationOptions.getTargetNodeRef(), parameters);
    // putParameterIfNotNull(ImageRenderingEngine.PARAM_ASSOC_NAME, assocDetails.getAssociationName(), parameters);
    // putParameterIfNotNull(ImageRenderingEngine.PARAM_ASSOC_TYPE, assocDetails.getAssociationType(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_TIMEOUT_MS, transformationOptions.getTimeoutMs(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_READ_LIMIT_TIME_MS, transformationOptions.getReadLimitTimeMs(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_MAX_SOURCE_SIZE_K_BYTES, transformationOptions.getMaxSourceSizeKBytes(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_READ_LIMIT_K_BYTES, transformationOptions.getReadLimitKBytes(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_MAX_PAGES, transformationOptions.getMaxPages(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_PAGE_LIMIT, transformationOptions.getPageLimit(), parameters);
    putParameterIfNotNull(AbstractTransformationRenderingEngine.PARAM_USE, transformationOptions.getUse(), parameters);
    if (transformationOptions instanceof SWFTransformationOptions) {
        SWFTransformationOptions swfTransformationOptions = (SWFTransformationOptions) transformationOptions;
        putParameterIfNotNull(ReformatRenderingEngine.PARAM_FLASH_VERSION, swfTransformationOptions.getFlashVersion(), parameters);
    } else if (transformationOptions instanceof ImageTransformationOptions) {
        ImageTransformationOptions imTransformationOptions = (ImageTransformationOptions) transformationOptions;
        putParameterIfNotNull(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, imTransformationOptions.getCommandOptions(), parameters);
        putParameterIfNotNull(ImageRenderingEngine.PARAM_AUTO_ORIENTATION, imTransformationOptions.isAutoOrient(), parameters);
        ImageResizeOptions imgResizeOptions = imTransformationOptions.getResizeOptions();
        if (imgResizeOptions != null) {
            int width = imgResizeOptions.getWidth();
            parameters.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, width);
            int height = imgResizeOptions.getHeight();
            parameters.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, height);
            boolean maintainAspectRatio = imgResizeOptions.isMaintainAspectRatio();
            parameters.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, maintainAspectRatio);
            boolean percentResize = imgResizeOptions.isPercentResize();
            parameters.put(ImageRenderingEngine.PARAM_IS_PERCENT_RESIZE, percentResize);
            boolean resizeToThumbnail = imgResizeOptions.isResizeToThumbnail();
            parameters.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, resizeToThumbnail);
            boolean allowEnlargement = imgResizeOptions.getAllowEnlargement();
            parameters.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, allowEnlargement);
        }
    }
    if (transformationOptions.getSourceOptionsList() != null) {
        for (TransformationSourceOptions sourceOptions : transformationOptions.getSourceOptionsList()) {
            sourceOptions.getSerializer().serialize(sourceOptions, parameters);
        }
    }
    // TODO Handle RuntimeExecutableTransformationOptions
    return parameters;
}
Also used : Serializable(java.io.Serializable) SWFTransformationOptions(org.alfresco.repo.content.transform.swf.SWFTransformationOptions) HashMap(java.util.HashMap) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) TransformationSourceOptions(org.alfresco.service.cmr.repository.TransformationSourceOptions)

Aggregations

ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)23 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)22 Test (org.junit.Test)15 HashMap (java.util.HashMap)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)5 PagedSourceOptions (org.alfresco.service.cmr.repository.PagedSourceOptions)5 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)5 Serializable (java.io.Serializable)4 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 RuntimeExecutableContentTransformerOptions (org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerOptions)2 CropSourceOptions (org.alfresco.service.cmr.repository.CropSourceOptions)2 ThumbnailParentAssociationDetails (org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1