Clover icon

Magnolia Imaging Module 3.2.3

  1. Project Clover database Fri Nov 6 2015 14:54:03 CET
  2. Package info.magnolia.imaging.operations

File ImageOperationChainTest.java

 

Code metrics

0
57
2
1
143
81
2
0.04
28.5
2
1

Classes

Class Line # Actions
ImageOperationChainTest 59 57 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2015 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging.operations;
35   
36    import info.magnolia.imaging.AbstractImagingTest;
37    import info.magnolia.imaging.StringParameterProvider;
38    import info.magnolia.imaging.operations.cropresize.AutoCropAndResize;
39    import info.magnolia.imaging.operations.load.Blank;
40    import info.magnolia.imaging.operations.load.ClasspathImageLoader;
41    import info.magnolia.imaging.operations.text.FixedText;
42    import info.magnolia.imaging.operations.text.HorizontalAlignment;
43    import info.magnolia.imaging.operations.text.TextStyle;
44    import info.magnolia.imaging.operations.text.VerticalAlignment;
45   
46    import java.awt.Color;
47    import java.awt.image.BufferedImage;
48    import java.io.FileOutputStream;
49   
50    import javax.imageio.ImageIO;
51   
52    import org.junit.Test;
53   
54    import com.jhlabs.image.WoodFilter;
55   
56    /**
57    * Tests for {@link info.magnolia.imaging.operations.ImageOperationChain}.
58    */
 
59    public class ImageOperationChainTest extends AbstractImagingTest {
60   
61    //TODO - test that nested chains on several level work too
 
62  1 toggle @Test
63    public void testBlankAndWood() throws Exception {
64  1 final ImageOperationChain<StringParameterProvider> filterChain = new ImageOperationChain<StringParameterProvider>();
65   
66  1 final Blank blank = new Blank();
67  1 blank.setWidth(600);
68  1 blank.setHeight(400);
69  1 blank.setBackgroundColor(Color.red);
70  1 filterChain.addOperation(blank);
71   
72  1 final WoodFilter wood = new WoodFilter();
73  1 wood.setRings(0.3f);
74  1 wood.setFibres(0.1f);
75  1 wood.setStretch(4f);
76   
77  1 final BufferedImageOpDelegate woodW = new BufferedImageOpDelegate();
78  1 woodW.setDelegate(wood);
79  1 filterChain.addOperation(woodW);
80   
81  1 final StringParameterProvider p = new StringParameterProvider("hello");
82   
83  1 final BufferedImage result = filterChain.generate(p);
84   
85  1 ImageIO.write(result, "jpg", new FileOutputStream(newOutputFile("test-blank", "jpg")));
86  1 ImageIO.write(result, "png", new FileOutputStream(newOutputFile("test-blank", "png")));
87    }
88   
 
89  1 toggle @Test
90    public void testSomeTransformations() throws Exception {
91   
92  1 final ImageOperationChain<StringParameterProvider> filterChain = new ImageOperationChain<StringParameterProvider>();
93  1 final ClasspathImageLoader<StringParameterProvider> loader = new ClasspathImageLoader<StringParameterProvider>();
94  1 loader.setSrc("/IMG_1937.JPG");
95  1 filterChain.addOperation(loader);
96   
97   
98  1 final AutoCropAndResize cropAndResize = new AutoCropAndResize();
99  1 cropAndResize.setTargetHeight(200);
100  1 cropAndResize.setTargetWidth(600);
101  1 filterChain.addOperation(cropAndResize);
102   
103  1 final TextStyle txtStyle = new TextStyle();
104  1 txtStyle.setFontName("Arial");
105  1 txtStyle.setColor(Color.red);
106  1 txtStyle.setFontSize(40);
107  1 txtStyle.setFontStyle(1);
108   
109  1 final FixedText topLeft = new FixedText();
110  1 topLeft.setX(10);
111  1 topLeft.setY(10);
112  1 topLeft.setHorizontalAlign(HorizontalAlignment.left);
113  1 topLeft.setVerticalAlign(VerticalAlignment.top);
114  1 topLeft.setTextStyle(txtStyle);
115  1 topLeft.setText("top left");
116  1 filterChain.addOperation(topLeft);
117   
118  1 final FixedText center = new FixedText();
119  1 center.setX(10);
120  1 center.setY(10);
121  1 center.setHorizontalAlign(HorizontalAlignment.center);
122  1 center.setVerticalAlign(VerticalAlignment.middle);
123  1 center.setTextStyle(txtStyle);
124  1 center.setText("ceeeenter");
125  1 filterChain.addOperation(center);
126   
127  1 final FixedText rightBottom = new FixedText();
128  1 rightBottom.setX(10);
129  1 rightBottom.setY(10);
130  1 rightBottom.setHorizontalAlign(HorizontalAlignment.right);
131  1 rightBottom.setVerticalAlign(VerticalAlignment.bottom);
132  1 rightBottom.setTextStyle(txtStyle);
133  1 rightBottom.setText("right bottom");
134  1 filterChain.addOperation(rightBottom);
135   
136  1 final StringParameterProvider p = new StringParameterProvider("hello");
137   
138  1 final BufferedImage result = filterChain.generate(p);
139   
140  1 ImageIO.write(result, "png", new FileOutputStream(newOutputFile("test-result", "png")));
141    }
142   
143    }