Search in sources :

Example 31 with ImageTransformationOptions

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

the class ThumbnailServiceImplTest method testCreateThumbnailFromImage.

@Test
public void testCreateThumbnailFromImage() throws Exception {
    checkTransformer();
    NodeRef jpgOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG);
    NodeRef gifOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_GIF);
    // ===== small: 64x64, marked as thumbnail ====
    ImageResizeOptions imageResizeOptions = new ImageResizeOptions();
    imageResizeOptions.setWidth(64);
    imageResizeOptions.setHeight(64);
    imageResizeOptions.setResizeToThumbnail(true);
    ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions();
    imageTransformationOptions.setResizeOptions(imageResizeOptions);
    // ThumbnailDetails createOptions = new ThumbnailDetails();
    NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "small");
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "small", 1)));
    checkRendition("small", thumbnail1);
    outputThumbnailTempContentLocation(thumbnail1, "jpg", "small - 64x64, marked as thumbnail");
    // ===== small2: 64x64, aspect not maintained ====
    ImageResizeOptions imageResizeOptions2 = new ImageResizeOptions();
    imageResizeOptions2.setWidth(64);
    imageResizeOptions2.setHeight(64);
    imageResizeOptions2.setMaintainAspectRatio(false);
    ImageTransformationOptions imageTransformationOptions2 = new ImageTransformationOptions();
    imageTransformationOptions2.setResizeOptions(imageResizeOptions2);
    // ThumbnailDetails createOptions2 = new ThumbnailDetails();
    NodeRef thumbnail2 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions2, "small2");
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "small2", 1)));
    checkRendition("small2", thumbnail2);
    outputThumbnailTempContentLocation(thumbnail2, "jpg", "small2 - 64x64, aspect not maintained");
    // ===== half: 50%x50 =====
    ImageResizeOptions imageResizeOptions3 = new ImageResizeOptions();
    imageResizeOptions3.setWidth(50);
    imageResizeOptions3.setHeight(50);
    imageResizeOptions3.setPercentResize(true);
    ImageTransformationOptions imageTransformationOptions3 = new ImageTransformationOptions();
    imageTransformationOptions3.setResizeOptions(imageResizeOptions3);
    // ThumbnailDetails createOptions3 = new ThumbnailDetails();
    NodeRef thumbnail3 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions3, "half");
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "half", 1)));
    checkRendition("half", thumbnail3);
    outputThumbnailTempContentLocation(thumbnail3, "jpg", "half - 50%x50%");
    // ===== half2: 50%x50 from gif =====
    ImageResizeOptions imageResizeOptions4 = new ImageResizeOptions();
    imageResizeOptions4.setWidth(50);
    imageResizeOptions4.setHeight(50);
    imageResizeOptions4.setPercentResize(true);
    ImageTransformationOptions imageTransformationOptions4 = new ImageTransformationOptions();
    imageTransformationOptions4.setResizeOptions(imageResizeOptions4);
    // ThumbnailDetails createOptions4 = new ThumbnailDetails();
    NodeRef thumbnail4 = this.thumbnailService.createThumbnail(gifOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions4, "half2");
    checkRenditioned(gifOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "half2", 1)));
    checkRendition("half2", thumbnail4);
    outputThumbnailTempContentLocation(thumbnail4, "jpg", "half2 - 50%x50%, from gif");
}
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 32 with ImageTransformationOptions

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

the class ThumbnailServiceImplTest method testDuplicationNames.

@Test
public void testDuplicationNames() throws Exception {
    checkTransformer();
    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);
    // ThumbnailDetails createOptions = new ThumbnailDetails();
    NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "small");
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "small", 1)));
    checkRendition("small", thumbnail1);
    // the origional thumbnail is returned if we are attempting to create a duplicate
    NodeRef duplicate = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "small");
    assertNotNull(duplicate);
    assertEquals(duplicate, 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 33 with ImageTransformationOptions

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

the class ThumbnailServiceImplTest method testCreateRenditionThumbnailFromPdfPage2.

@Test
public void testCreateRenditionThumbnailFromPdfPage2() throws Exception {
    ImageTransformationOptions options = new ImageTransformationOptions();
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber(new Integer(2));
    pagedSourceOptions.setEndPageNumber(new Integer(2));
    options.addSourceOptions(pagedSourceOptions);
    ThumbnailDefinition thumbnailDefinition = new ThumbnailDefinition(MimetypeMap.MIMETYPE_PDF, options, "doclib_2");
    thumbnailService.getThumbnailRegistry().addThumbnailDefinition(thumbnailDefinition);
    checkTransformer();
    NodeRef pdfOrig = createOriginalContent(this.folder, MimetypeMap.MIMETYPE_PDF);
    NodeRef thumbnail0 = this.thumbnailService.createThumbnail(pdfOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, thumbnailDefinition.getTransformationOptions(), "doclib_2");
    assertNotNull(thumbnail0);
    checkRenditioned(pdfOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "doclib_2", 1)));
    checkRendition("doclib_2", thumbnail0);
    // Check the length
    File tempFile = TempFileProvider.createTempFile("thumbnailServiceImplTest", ".jpg");
    ContentReader reader = this.contentService.getReader(thumbnail0, ContentModel.PROP_CONTENT);
    long size = reader.getSize();
    reader.getContent(tempFile);
    assertTrue("Page 2 should be blank and less than 4500 bytes. It was " + size + " bytes. tempFile=" + tempFile.getPath(), size < 4500);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentReader(org.alfresco.service.cmr.repository.ContentReader) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) File(java.io.File) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 34 with ImageTransformationOptions

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

the class ThumbnailServiceImplTest method testThumbnailServiceCreateApi.

@Test
public void testThumbnailServiceCreateApi() throws Exception {
    // Create a second folder
    Map<QName, Serializable> folderProps = new HashMap<QName, Serializable>();
    folderProps.put(ContentModel.PROP_NAME, "otherTestFolder");
    NodeRef otherFolder = this.secureNodeService.createNode(this.rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "otherTestFolder"), ContentModel.TYPE_FOLDER).getChildRef();
    checkTransformer();
    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);
    // Create thumbnail - same MIME type
    NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, "smallJpeg");
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "smallJpeg", 1)));
    checkRendition("smallJpeg", thumbnail1);
    outputThumbnailTempContentLocation(thumbnail1, "jpg", "smallJpeg - 64x64, marked as thumbnail");
    // Create thumbnail - different MIME type
    thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_PNG, imageTransformationOptions, "smallPng");
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "smallPng", 1)));
    checkRendition("smallPng", thumbnail1);
    outputThumbnailTempContentLocation(thumbnail1, "png", "smallPng - 64x64, marked as thumbnail");
    // Removd code: We now automatically discard all extra command options for security reasons.
    // Create thumbnail - different target assoc details
    ThumbnailParentAssociationDetails tpad = new ThumbnailParentAssociationDetails(otherFolder, QName.createQName(NamespaceService.RENDITION_MODEL_1_0_URI, "foo"), QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "bar"));
    thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_PNG, imageTransformationOptions, "targetDetails", tpad);
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, "targetDetails", 1)));
    checkRendition("targetDetails", thumbnail1);
    outputThumbnailTempContentLocation(thumbnail1, "png", "targetDetails - 64x64, marked as thumbnail");
    // Create thumbnail - null thumbnail name
    thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_PNG, imageTransformationOptions, null);
    assertNotNull(thumbnail1);
    checkRenditioned(jpgOrig, Collections.singletonList(new ExpectedAssoc(RegexQNamePattern.MATCH_ALL, null, 4)));
    checkRendition(null, thumbnail1);
    outputThumbnailTempContentLocation(thumbnail1, "png", "'null' - 64x64, marked as thumbnail");
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) ThumbnailParentAssociationDetails(org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest) Test(org.junit.Test) AbstractContentTransformerTest(org.alfresco.repo.content.transform.AbstractContentTransformerTest)

Example 35 with ImageTransformationOptions

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

the class ThumbnailServiceImplParameterTest method createThumbnailPassesParametersToActionService.

/**
 * This test method ensures that the parameters on thumbnail-create are
 * passed through the RenditionService to the ActionService
 */
@Test
public void createThumbnailPassesParametersToActionService() {
    // As most of the services are mocked out, the actual values used here
    // don't matter.
    final Map<String, Serializable> parametersUnderTest = new HashMap<String, Serializable>();
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, new Integer(42));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, new Integer(93));
    parametersUnderTest.put(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, "foo");
    parametersUnderTest.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, Boolean.TRUE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, Boolean.FALSE);
    parametersUnderTest.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, Boolean.TRUE);
    parametersUnderTest.put(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, ContentModel.PROP_CONTENT);
    parametersUnderTest.put(RenditionService.PARAM_DESTINATION_NODE, dummyNodeRef2);
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE, new Integer(2));
    parametersUnderTest.put(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE, new Integer(2));
    parametersUnderTest.put(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET, "00:00:00.5");
    ImageTransformationOptions imageTransOpts = new ImageTransformationOptions();
    imageTransOpts.setTargetNodeRef(dummyNodeRef2);
    imageTransOpts.setTargetContentProperty((QName) parametersUnderTest.get(ImageRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY));
    imageTransOpts.setCommandOptions((String) parametersUnderTest.get(ImageRenderingEngine.PARAM_COMMAND_OPTIONS));
    ImageResizeOptions resizeOptions = new ImageResizeOptions();
    resizeOptions.setHeight((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_HEIGHT));
    resizeOptions.setWidth((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_WIDTH));
    resizeOptions.setMaintainAspectRatio((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO));
    resizeOptions.setResizeToThumbnail((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL));
    resizeOptions.setAllowEnlargement((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT));
    imageTransOpts.setResizeOptions(resizeOptions);
    PagedSourceOptions pagedSourceOptions = new PagedSourceOptions();
    pagedSourceOptions.setStartPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_START_PAGE));
    pagedSourceOptions.setEndPageNumber((Integer) parametersUnderTest.get(PagedSourceOptionsSerializer.PARAM_SOURCE_END_PAGE));
    imageTransOpts.addSourceOptions(pagedSourceOptions);
    TemporalSourceOptions temporalSourceOptions = new TemporalSourceOptions();
    temporalSourceOptions.setOffset((String) parametersUnderTest.get(TemporalSourceOptionsSerializer.PARAM_SOURCE_TIME_OFFSET));
    imageTransOpts.addSourceOptions(temporalSourceOptions);
    ThumbnailParentAssociationDetails assocDetails = new ThumbnailParentAssociationDetails(dummyNodeRef3, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "homerSimpson"));
    // Now request the creation of the the thumbnail.
    thumbnailService.createThumbnail(dummyNodeRef1, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransOpts, "bartSimpson", assocDetails);
    ArgumentCaptor<Action> argument = ArgumentCaptor.forClass(Action.class);
    verify(mockActionService).executeAction(argument.capture(), any(NodeRef.class), anyBoolean(), anyBoolean());
    final Action action = argument.getValue();
    final RenditionDefinition renditionDefn = (RenditionDefinition) action;
    Map<String, Serializable> parameters = renditionDefn.getParameterValues();
    for (String s : parametersUnderTest.keySet()) {
        if (parameters.keySet().contains(s) == false || parameters.get(s) == null || parameters.get(s).toString().length() == 0) {
            fail("Missing parameter " + s);
        }
        assertEquals("Parameter " + s + " had wrong value.", parametersUnderTest.get(s), parameters.get(s));
    }
}
Also used : TemporalSourceOptions(org.alfresco.service.cmr.repository.TemporalSourceOptions) Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) HashMap(java.util.HashMap) ImageTransformationOptions(org.alfresco.repo.content.transform.magick.ImageTransformationOptions) PagedSourceOptions(org.alfresco.service.cmr.repository.PagedSourceOptions) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ImageResizeOptions(org.alfresco.repo.content.transform.magick.ImageResizeOptions) ThumbnailParentAssociationDetails(org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) Test(org.junit.Test)

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