Search in sources :

Example 16 with Layer

use of com.day.image.Layer in project acs-aem-commons by Adobe-Consulting-Services.

the class LetterPillarBoxImageTransformerImplTest method testTransform_withColor.

@Test
public void testTransform_withColor() throws Exception {
    final int width = 400;
    final int height = 225;
    final String color = "ABCDEF";
    final float alpha = 0.5f;
    final int alphaint = Math.round(255 * alpha);
    Color expected = new Color(171, 205, 239, alphaint);
    map.put("width", width);
    map.put("height", height);
    map.put("color", color);
    map.put("alpha", alpha);
    ValueMap properties = new ValueMapDecorator(map);
    final Layer mockLayer = mock(Layer.class);
    when(layer.getWidth()).thenReturn(START_WIDTH, START_WIDTH, width);
    when(layer.getHeight()).thenReturn(START_HEIGHT, START_HEIGHT, height);
    doNothing().when(mockLayer).blit(any(Layer.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt());
    final Transformer transformer = new Transformer(mockLayer);
    transformer.transform(layer, properties);
    assertTrue("Layer constructor was not intercepted.", transformer.layerCreated);
    verify(layer, times(3)).getWidth();
    verify(layer, times(3)).getHeight();
    verify(layer, times(1)).resize(width, height);
    verify(mockLayer, times(1)).blit(layer, 0, 0, width, height, 0, 0);
    verifyNoMoreInteractions(layer);
    verifyNoMoreInteractions(mockLayer);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Layer(com.day.image.Layer) Test(org.junit.Test)

Example 17 with Layer

use of com.day.image.Layer in project acs-aem-commons by Adobe-Consulting-Services.

the class LetterPillarBoxImageTransformerImplTest method testTransform_onlyWidth.

@Test
public void testTransform_onlyWidth() throws Exception {
    final int width = 400;
    final int height = 225;
    map.put("width", width);
    ValueMap properties = new ValueMapDecorator(map);
    final Layer mockLayer = mock(Layer.class);
    final Transformer transformer = new Transformer(mockLayer);
    when(layer.getWidth()).thenReturn(START_WIDTH, START_WIDTH, width);
    when(layer.getHeight()).thenReturn(START_HEIGHT, START_HEIGHT, height);
    doNothing().when(mockLayer).blit(any(Layer.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt());
    transformer.transform(layer, properties);
    assertNotNull("Layer constructor was not intercepted.", transformer.layerCreated);
    verify(layer, times(3)).getWidth();
    verify(layer, times(3)).getHeight();
    verify(layer, times(1)).resize(width, height);
    verify(mockLayer, times(1)).blit(layer, 0, 0, width, height, 0, 0);
    verifyNoMoreInteractions(layer);
    verifyNoMoreInteractions(mockLayer);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Layer(com.day.image.Layer) Test(org.junit.Test)

Example 18 with Layer

use of com.day.image.Layer in project acs-aem-commons by Adobe-Consulting-Services.

the class LetterPillarBoxImageTransformerImplTest method testTransform_withLetterBoxing.

@Test
public void testTransform_withLetterBoxing() throws Exception {
    final int width = 600;
    final int height = 600;
    final int calcHeight = 338;
    final int startPos = (width - calcHeight) / 2;
    map.put("width", width);
    map.put("height", height);
    ValueMap properties = new ValueMapDecorator(map);
    final Layer mockLayer = mock(Layer.class);
    final Transformer transformer = new Transformer(mockLayer);
    when(layer.getWidth()).thenReturn(START_WIDTH, START_WIDTH, width);
    when(layer.getHeight()).thenReturn(START_HEIGHT, START_HEIGHT, calcHeight);
    doNothing().when(mockLayer).blit(any(Layer.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt());
    transformer.transform(layer, properties);
    assertTrue("Layer constructor was not intercepted.", transformer.layerCreated);
    verify(layer, times(3)).getWidth();
    verify(layer, times(3)).getHeight();
    verify(layer, times(1)).resize(width, calcHeight);
    verify(mockLayer, times(1)).blit(layer, 0, startPos, width, calcHeight, 0, 0);
    verifyNoMoreInteractions(layer);
    verifyNoMoreInteractions(mockLayer);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Layer(com.day.image.Layer) Test(org.junit.Test)

Example 19 with Layer

use of com.day.image.Layer in project acs-aem-commons by Adobe-Consulting-Services.

the class LetterPillarBoxImageTransformerImplTest method testTransform_onlyHeight.

@Test
public void testTransform_onlyHeight() throws Exception {
    final int width = 400;
    final int height = 225;
    map.put("height", height);
    ValueMap properties = new ValueMapDecorator(map);
    final Layer mockLayer = mock(Layer.class);
    final Transformer transformer = new Transformer(mockLayer);
    when(layer.getWidth()).thenReturn(START_WIDTH, START_WIDTH, width);
    when(layer.getHeight()).thenReturn(START_HEIGHT, START_HEIGHT, height);
    doNothing().when(mockLayer).blit(any(Layer.class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt());
    transformer.transform(layer, properties);
    assertNotNull("Layer constructor was not intercepted.", transformer.layerCreated);
    verify(layer, times(3)).getWidth();
    verify(layer, times(3)).getHeight();
    verify(layer, times(1)).resize(width, height);
    verify(mockLayer, times(1)).blit(layer, 0, 0, width, height, 0, 0);
    verifyNoMoreInteractions(layer);
    verifyNoMoreInteractions(mockLayer);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) Layer(com.day.image.Layer) Test(org.junit.Test)

Example 20 with Layer

use of com.day.image.Layer in project acs-aem-commons by Adobe-Consulting-Services.

the class NamedTransformImageServlet method getLayer.

/**
 * Gets the Image layer.
 *
 * @param image The Image to get the layer from
 * @return the image's Layer
 * @throws IOException
 */
private Layer getLayer(final Image image) throws IOException {
    Layer layer = null;
    try {
        layer = image.getLayer(false, false, false);
    } catch (RepositoryException ex) {
        log.error("Could not create layer");
    }
    if (layer == null) {
        log.error("Could not create layer - layer is null;");
    } else {
        image.crop(layer);
        image.rotate(layer);
    }
    return layer;
}
Also used : RepositoryException(javax.jcr.RepositoryException) Layer(com.day.image.Layer)

Aggregations

Layer (com.day.image.Layer)29 ValueMap (org.apache.sling.api.resource.ValueMap)10 Test (org.junit.Test)10 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)9 InputStream (java.io.InputStream)5 Resource (org.apache.sling.api.resource.Resource)4 Rendition (com.day.cq.dam.api.Rendition)3 Color (java.awt.Color)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Asset (com.day.cq.dam.api.Asset)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)2 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)2 NamedImageTransformer (com.adobe.acs.commons.images.NamedImageTransformer)1 WorkflowHelper (com.adobe.acs.commons.util.WorkflowHelper)1 AbstractImageTest (com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)1 DownloadResource (com.day.cq.commons.DownloadResource)1 ImageResource (com.day.cq.commons.ImageResource)1